mongodb 尽管字段存在,但按字段值搜索Mongo shell不会返回任何结果

vc6uscn9  于 2022-12-18  发布在  Go
关注(0)|答案(1)|浏览(102)

没有查询的搜索返回一些文档。然后我尝试通过字段值查询其中一个文档,但查询没有返回任何内容:'

> db.packageData.find( { },{data : 0} ).limit(2).pretty()
{
        "_id" : "RB#0122SS01CT1_20221024_164223_00116723.xml_1666644148902",
        "filename" : "0122SS01CT1_20221024_164223_00116723.xml",
        "p_uid" : "0122SS01CT1_20221024_164223_00116723",
        "tunnelPackageId" : NumberLong(116723),
        "userId" : "RB",
        "contentType" : "CAMERA_XML",
        "length" : 13652,
        "uploadDate" : ISODate("2022-10-24T20:42:28.902Z"),
        "forwardDate" : ISODate("2022-10-24T20:42:28.903Z"),
        "forwarded" : false
}
{
        "_id" : "TOP#0122SS01CT1_20221024_164225_00116726_3.jpg_1666644148991",
        "filename" : "0122SS01CT1_20221024_164225_00116726_3.jpg",
        "p_uid" : "0122SS01CT1_20221024_164225_00116726",
        "tunnelPackageId" : NumberLong(116726),
        "userId" : "TOP",
        "contentType" : "THUMBNAIL_IMAGE",
        "length" : 34556,
        "uploadDate" : ISODate("2022-10-24T20:42:28.991Z"),
        "forwardDate" : ISODate("2022-10-24T20:42:28.991Z"),
        "forwarded" : false
}
> db.packageData.find( { "filename" : "0122SS01CT1_20221024_164223_00116723.xml" },{data : 0} ).pretty()
>

谢谢你的建议!'我试着转义文件名值中的.””,但得到了相同的结果。

llycmphe

llycmphe1#

你做错了什么,看看我为你的数据得到的输出:

MongoDB Enterprise replset:PRIMARY> db.coll.insertOne({
...         "_id" : "RB#0122SS01CT1_20221024_164223_00116723.xml_1666644148902",
...         "filename" : "0122SS01CT1_20221024_164223_00116723.xml",
...         "p_uid" : "0122SS01CT1_20221024_164223_00116723",
...         "tunnelPackageId" : NumberLong(116723),
...         "userId" : "RB",
...         "contentType" : "CAMERA_XML",
...         "length" : 13652,
...         "uploadDate" : ISODate("2022-10-24T20:42:28.902Z"),
...         "forwardDate" : ISODate("2022-10-24T20:42:28.903Z"),
...         "forwarded" : false
... })
{
        "acknowledged" : true,
        "insertedId" : "RB#0122SS01CT1_20221024_164223_00116723.xml_1666644148902"
}
MongoDB Enterprise replset:PRIMARY> db.coll.find( { },{data : 0} ).limit(2).pretty()
{
        "_id" : "RB#0122SS01CT1_20221024_164223_00116723.xml_1666644148902",
        "filename" : "0122SS01CT1_20221024_164223_00116723.xml",
        "p_uid" : "0122SS01CT1_20221024_164223_00116723",
        "tunnelPackageId" : NumberLong(116723),
        "userId" : "RB",
        "contentType" : "CAMERA_XML",
        "length" : 13652,
        "uploadDate" : ISODate("2022-10-24T20:42:28.902Z"),
        "forwardDate" : ISODate("2022-10-24T20:42:28.903Z"),
        "forwarded" : false
}
MongoDB Enterprise replset:PRIMARY> db.coll.find( { "filename" : "0122SS01CT1_20221024_164223_00116723.xml" },{data : 0} ).pretty()
{
        "_id" : "RB#0122SS01CT1_20221024_164223_00116723.xml_1666644148902",
        "filename" : "0122SS01CT1_20221024_164223_00116723.xml",
        "p_uid" : "0122SS01CT1_20221024_164223_00116723",
        "tunnelPackageId" : NumberLong(116723),
        "userId" : "RB",
        "contentType" : "CAMERA_XML",
        "length" : 13652,
        "uploadDate" : ISODate("2022-10-24T20:42:28.902Z"),
        "forwardDate" : ISODate("2022-10-24T20:42:28.903Z"),
        "forwarded" : false
}

相关问题