简体   繁体   English

你如何在mongo dart中搜索一系列文档?

[英]How do you search an array of documents in mongo dart?

How do I search an array of documents in mongodb using the dart programming language? 如何使用dart编程语言在mongodb中搜索文档数组?

Im using https://pub.dartlang.org/packages/mongo_dart for the driver 我使用https://pub.dartlang.org/packages/mongo_dart作为驱动程序

The example db collection looks like this 示例db集合如下所示

"name": [ {"full":"Tyler Thompson", "first":"Tyler", "last":"Thompson" } ]

Using the following query will help achieve your goal for the one name 使用以下查询将有助于实现您的一个名称的目标

String search = "Tyler";

{"name.full": {'\\$regex': '${search}'}

Hope that helps! 希望有所帮助! Couldn't find an example, so I thought I'd give one!:) 找不到一个例子,所以我想我会给一个!:)

You can try to look at https://github.com/vadimtsushko/mongo_dart/blob/master/example/queries.dart 您可以尝试查看https://github.com/vadimtsushko/mongo_dart/blob/master/example/queries.dart

It is plausible that for your sample something like this would work: 对于您的样本,这样的事情是可行的:

coll.find(where.eq('name.full','Tyler'))

or maybe 或者可能

coll.find(where.match('name.full','^Tyl[eo]r'))

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

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