我正在尝试在MongoDB中创建一个集合,但出现错误:
“名称”字段不是有效的收集选项
我正在使用MongoDB 4.0.0版。代码:
const MongoClient = require('mongodb').MongoClient;
MongoClient.connect('mongodb://localhost:27017/newApp', (err, db) =>{
if (err) {
return console.log('mongodb connection error');
}
db.createCollection('people', {
name: 'sarah',
age: 27,
location: 'honolului',
relationship: 'unknown'
}, (err, result) => {
if (err) {
return console.log('query has not successed retry error code ' + err);
}
conole.log(result.ops);
});
});
答案 0 :(得分:0)
mongodb中的集合没有定义的属性。 createCollection的第二个参数是options。您可以在这里检查。 https://docs.mongodb.com/manual/reference/method/db.createCollection/
答案 1 :(得分:0)
您使用它的方式有误,您必须像这样使用它:
获得更多帮助:
https://docs.mongodb.com/manual/reference/method/db.createCollection/
config('auth.defaults.guard');
Auth::getDefaultDriver();
注意: :验证器将为您提供应用自定义验证方法的选项,例如db.createCollection( "people", {
validator: { $jsonSchema: {
bsonType: "object",
required: [ "phone" ],
properties: {
name: {
bsonType: "string",
description: "must be a string and is required"
},
age: {
bsonType : "number",
description: "must be a number and match the regular expression pattern"
},
location: {
bsonType: "string",
description: "must be a string"
},
relationship: {
bsonType: "string",
description: "can only be one of the enum values"
}
}
} }
} )
或required
。