【问题标题】:Loading Data into MongoDB using external script使用外部脚本将数据加载到 MongoDB
【发布时间】:2017-05-02 01:49:55
【问题描述】:

我有一个脚本,我正在使用 mongo shell 使用 load() 方法加载一些初始数据。但它似乎在第一行就失败了,出现以下错误

TypeError: db.getSibilingDB 不是函数

这是我的脚本

db = db.getSibilingDB('queued')
db.createCollection('restaurantList')
restaurantListCollection = db.getCollection('restaurantList')
restaurantListCollection.remove({})
restaurantListCollection.insert({
    name:"RestaurantA",
    address: "Cherry Street 14",
    waitTime: "15-20"
})
restaurantListCollection.insert({
    name:"RestaurantB",
    address: "Columbus Street 29",
    waitTime: "5-7"
})
restaurantListCollection.insert({
    name:"RestaurantA",
    address: "12th Street",
    waitTime: "10-15"
})

【问题讨论】:

  • db.getSibilingDB('queued') 中的db 很可能不是 mongodb 数据库实例,但从您的示例中无法判断。
  • @Jthorpe 您能否详细说明一下,db 变量需要事先发生什么
  • @Jthorpe 这就是我拥有的所有代码,之后我所做的就是在我的 mongo shell 中使用 load('loadDB.js') 。我不确定在此之前是否还必须做其他事情

标签: node.js mongodb mongoose


【解决方案1】:

您在getSibilingDB 中似乎有拼写错误。 这可以解释为什么 db 对象似乎没有一个名为那个的函数。

把它改成getSiblingDB,('b'和'l'之间没有'i')

希望这能解决问题!

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2020-06-05
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-06-11
    • 2013-03-16
    • 2013-09-10
    相关资源
    最近更新 更多