【发布时间】: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') 。我不确定在此之前是否还必须做其他事情