简体   繁体   English

按 ObjectID 重划 MongoDB 查询

[英]Redash MongoDB query by ObjectID

I have a collection with the following document structure:我有一个具有以下文档结构的集合:

{
    "_id" : ObjectId("58aa706c658d1dc6c700002c"),
    "source" : "web",
    "type" : "Comentarios",
    "email" : "jhondoe@xyz.com",
    "updated_at" : ISODate("2017-02-20T04:28:28.623Z"),
    "created_at" : ISODate("2017-02-20T04:28:28.623Z")
}

I need to build a query in Redash Syntax to get a document by '_id'.我需要在Redash 语法中构建一个查询以通过“_id”获取文档。 I built the following query but always I got an error: "Invalid query format. The query is not a valid JSON."我构建了以下查询,但总是出现错误:“查询格式无效。查询不是有效的 JSON。”

{
    "collection": "commerce_messages",
    "query" : {
        "_id": "ObjectId(58aa706c658d1dc6c700002c)"
    }
}

I tried enclosing the ObjectId on quotes but the query does not return results.我尝试将 ObjectId 括在引号中,但查询不返回结果。

The only documentation I have found about this is in this link: https://redash.io/help/queries/querying_mongodb.html but they do not explain how to query for ObjectId.我在此链接中找到的唯一文档: https : //redash.io/help/queries/querying_mongodb.html但它们没有解释如何查询 ObjectId。

The redash FAQ for querying MongoDB claims they support MongoDB Extended JSON用于查询 MongoDB的 redash FAQ声称他们支持MongoDB Extended JSON

The syntax to query by ObjectId is:通过 ObjectId 查询的语法是:

{
    "collection": "commerce_messages",
    "query": {
        "_id": {
            "$oid": "58aa706c658d1dc6c700002c"
        }
    }
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM