我有一个字符串列表,其中包含给定星期几的日期。
String daysweek[] = ["10/05/2020", "11/05/2020", "12/05/2020", "13/05/2020", "14/05/2020", "15/05/2020", "16/05/2020" ]
我的目标是能够找到属于某个星期的多个文档。比较字段是“第一天”。
遵循数据库中文档结构的图像:
Document insert = new Document().append("$elemMatch", daysweek[]);
Document filterstar = new Document().append("id_motorista", idmotorista).append("pagamento", false).append("firstday", insert);
coll.find(filterstar).projection(new Document().append("_id", 1).append("origem",1).append("destino", 1).append("formadepagamento", 1).append("valordaviagem",1)
.append("notamotorista",1).append("pagamento",1).append("iniciodaviagem", 1).append("fimdaviagem",1).append("viagemcancelada", 1).append("horadaaceitacao",1)
.append("horacancelamentomotorista", 1).append("horacancelamentousuario", 1).append("taxadecancelamento", 1).append("valordaviagemmotorista", 1).append("valordaviagemusuario", 1).append("id_acompanhamento",1)
.append("taxaaplicativo", 1).append("taxacartao", 1).append("taxamotorista", 1)).sort(new Document().append("firstday", 1)).limit(100)
.into(docs).addOnSuccessListener(new OnSuccessListener<List<Document>>() {
@Override
public void onSuccess(List<Document> documents) {}
但是搜索没有找到文件。预期的查询数量为35。
我想知道是否有任何方法可以通过给定的文档字段查找文档,匹配arraylist中的任何项目。
$ elemMatch用于查询数组字段,但是在您的方案中,查询字符串字段并且输入是数组,则可以只使用$ in运算符。
Mongo Shell语法:
db.collection.find({firstday : {$in : ["10/05/2020", "11/05/2020", "12/05/2020", "13/05/2020", "14/05/2020", "15/05/2020", "16/05/2020"]}})
测试: mongoplayground
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句