语法错误意外的令牌ILLEGAL Mongo控制台

时间:2015-05-18 09:27:05

标签: mongodb

我尝试从阵列threads中删除文档,该文档是集合头文档中的一个字段。

在Mongodb控制台中,我编写以下查询:

db.inboxes.update({}, { $pull: {threads: {"_id":ObjectId(”5550b41ce7c33013c8000006”)}}})

但我一直在接受:

  

意外的令牌ILLEGAL

这让我发疯了。 Collection的架构如下:

var inboxSchema = mongoose.Schema({
    user: {
        type: mongoose.Schema.ObjectId,
        ref: 'userSchema',
        required: true
    },
    threads: [{
        name: String,
        guid: String,
        with: {
            _id: {
                type: mongoose.Schema.ObjectId,
                ref: 'userSchema'
            },
            name: {
                username: String,
                firstname: String,
                lastname: String
            },
            email: {
                type: String,
                match: /\S+@\S+\.\S+/
            }
        },
        messages: [{
            heading: String,
            sent: {
                type: Date,
                default: Date.now
            },
            from: {
                type: mongoose.Schema.ObjectId,
                ref: 'userSchema'
            },
            to: {
                type: mongoose.Schema.ObjectId,
                ref: 'userSchema'
            },
            body: String
        }],
        updated: {
            type: Date,
            default: Date.now
        },
        unreadMessage: Boolean
    }]
});

1 个答案:

答案 0 :(得分:1)

查看您的查询

db.inboxes.update({}, { $pull: {threads: {"_id":ObjectId(”5550b41ce7c33013c8000006”)}}})

ObjectId参数中

您的引号为而不是"。替换它们,你将摆脱错误:)