在创建新文档然后尝试插入新的子文档时,我收到此错误:
Object {error: "E11000 duplicate key error index: sales.users.$gro…p key:
{ : ObjectId('537b7788da19c4601d061d04') }"}
error: "E11000 duplicate key error index: sales.users.$groups.groupId_1
dup key: { : ObjectId('537b7788da19c4601d061d04') }"
__proto__: Object
Run Code Online (Sandbox Code Playgroud)
我试图插入的子文档被定义为子模式,其具有需要{unique:true},{sparse:true}的需求的groupId字段.我用来做upsert的mongoose方法调用是:
User.findByIdAndUpdate(userId,
{ $push: { 'groups': userUpdate} },
function (err, obj) where userUpdate = { groupId: groupId }.
Run Code Online (Sandbox Code Playgroud)
删除索引后问题得到解决,不再出现此错误.
var UserSchema = new Schema({
email: {
type: String,
required: true,
unique: true
},
active: {
type: Boolean,
default: true
},
username: {
type: String,
required: true,
unique: true
},
password: { …Run Code Online (Sandbox Code Playgroud) 我正在通过以下步骤在Windows环境中的本地系统上创建副本集
mkdir -p \srv\mongodb\rs0-0 \srv\mongodb\rs0-1 \srv\mongodb\rs0-2
mongod --port 27017 --dbpath \srv\mongodb\rs0-0 --replSet rs0 --smallfiles --oplogSize 128
mongod --port 27018 --dbpath \srv\mongodb\rs0-1 --replSet rs0 --smallfiles --oplogSize 128
mongod --port 27019 --dbpath \srv\mongodb\rs0-2 --replSet rs0 --smallfiles --oplogSize 128
Run Code Online (Sandbox Code Playgroud)
然后
mongo shell type mongo --port 27017
rs.initiate()
Run Code Online (Sandbox Code Playgroud)
但我得到了错误
"{ "ok" : 0, "errmsg" : "server is not running with --replSet" }"
Run Code Online (Sandbox Code Playgroud)
提前致谢
让我说我有[{1 2 3 4}].我如何追加{5 6 7 8}以便向量说出来[{1 2 3 4} {5 6 7 8}]
我想知道如何使用perl正则表达式匹配url中用连字符分隔的多个单词(包含空格).例如,
url = &name=abc&age=12&address=ab - cd&city=xyz;
url = &name=abc&age=12&address=abcd&city=xyz;
Run Code Online (Sandbox Code Playgroud)
在给定的URL中,我想单独匹配地址字段并将其替换为空.
我正在尝试这个,但它不匹配连字符和第一个网址后面的单词,但它适用于第二个网址.
url =~ s/\&address=(\w+)//g;
Run Code Online (Sandbox Code Playgroud)
任何帮助将不胜感激.