【问题标题】:Syntax error Unexpected token ILLEGAL Mongo Console语法错误 Unexpected token ILLEGAL Mongo Console
【发布时间】:2015-07-29 17:42:46
【问题描述】:

我正在尝试从数组threads 中删除一个文档,该数组是集合头文档中的一个字段。

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

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

但我不断得到:

意外令牌非法

这让我发疯。 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
    }]
});

【问题讨论】:

    标签: mongodb


    【解决方案1】:

    查看您的查询

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

    ObjectId 参数中,您有错误的引号 而不是"。替换它们,您将摆脱错误:)

    【讨论】:

    • 非常感谢!那天你真的帮助了我。但我压力太大,无法感谢你:)
    猜你喜欢
    • 2012-11-20
    • 1970-01-01
    • 1970-01-01
    • 2012-01-30
    • 2011-12-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多