简体   繁体   English

如何从值为“”的 mongo db 中排除数据

[英]How can I exclude data from mongo db whose value is ""

I have one excel sheet whose few row values are blank.我有一张 Excel 工作表,其中几行值为空白。 In MongoDB that values goes in the form of ""(when view in edit mode) When I try to retrieve the data excluding "" values.MongoDB ,值以“”的形式出现(在编辑模式下查看时)当我尝试检索不包括“”值的数据时。 I am still getting that.我仍然明白。

My query is as below.我的查询如下。

DrivetestdataLTE.find({
    latitude: { $ne:"" },
    longitude: { $ne:"" }}, { '_id': 0 }).lean().exec();
}

Saved data:保存的数据:


    "_id" : ObjectId("5de751d04a8590a009d4905a"),
    "log_hash" : "2.08E+17",
    "Time" : "33:23.7",
    "latitude" : "",
    "longitude" : "",

You can do something like this.你可以做这样的事情。

DrivetestdataLTE.find({
    latitude: { $ne:"" },
    longitude: { $ne:"" },{ '_id': 0 }}).exec();
}

you can find records, if field exist and value is empty您可以找到记录,如果字段存在且值为空

DrivetestdataLTE.find({ latitude: { $exists: true, $not: {$size: {"$gt":0}} }, longitude: { $exists: true, $not: {$size: {"$gt":0}} } })

or you can find if field is not exist或者您可以找到字段是否不存在

DrivetestdataLTE.find({ latitude: { $exists: false }, longitude: { $exists: false }  })

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

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