> db.createCollection('P12345');
{ "ok" : 0, "errmsg" : "collection already exists", "code" : 48 }
> db.createCollection('P123456');
{ "ok" : 1 }
> db.createCollection('P123451');
{ "ok" : 1 }
我正在尝试使用mongo本机驱动程序和node.js创建一个集合,
MongoClient.connect(url,{ useNewUrlParser: true },(err,client)=>{
if(err){
console.log(err);
}
const db = client.db('Customers');
db.createCollection('P987654321').then((result)=>{
console.log(result);
}).catch((err)=>{
console.log(err);
});
client.close();
})
但是我看到下面的错误形式正在运行此代码块。
{ MongoError: topology was destroyed
at executeCommand (F:\test\node_modules\mongodb\lib\operations\db_ops.js:473:21)
at db.listCollections.setReadPreference.toArray (F:\test\node_modules\mongodb\lib\operations\db_ops.js:232:7)
at result (F:\test\node_modules\mongodb\lib\utils.js:414:17)
at executeCallback (F:\test\node_modules\mongodb\lib\utils.js:406:9)
at handleCallback (F:\test\node_modules\mongodb\lib\utils.js:128:55)
at cursor.close (F:\test\node_modules\mongodb\lib\operations\cursor_ops.js:211:62)
at handleCallback (F:\test\node_modules\mongodb\lib\utils.js:128:55)
at completeClose (F:\test\node_modules\mongodb\lib\cursor.js:893:14)
at CommandCursor.Cursor.close (F:\test\node_modules\mongodb\lib\cursor.js:912:10)
at cursor._next (F:\test\node_modules\mongodb\lib\operations\cursor_ops.js:211:23) name: 'MongoError', [Symbol(mongoErrorContextSymbol)]: {} }