MongoDB Query Summary

Source: Internet
Author: User
Tags mongodb query

1, including date query from the start time to the end time

Basicdbobject queryobj = new Basicdbobject ();

Queryobj.put ("Date", new Basicdbobject (). Append ("$gte", StartTime). Append ("$lt", Endtime));

2, DISTINCT query

Basicdbobject queryobj = new Basicdbobject ();

Coll.distinct ("Field_name", queryobj);//Field_name the field name that needs to be distinct in the database, queryobj as the query condition, after the query condition is executed in distinct ; Returns a list containing all the non-repeating field_name.

This approach still has a medium defect, if the data volume is too large list may exceed the capacity, bad control, you can use the group by method to replace

3, exists query

Basicdbobject basicobj = new Basicdbobject ();
Basicdbobject andsearch = new Basicdbobject ();

Andsearch.put ("$gte", Start.gettime ()), Andsearch.put ("$lt", End.gettime ()), Basicobj.put ("date", Andsearch);

Basicobj.put ("Field_name", New Basicdbobject ("$exists", true)); If the database field_name This field has a value (including null), then the condition is met, whereas this record does not have this field is not eligible

4.

MongoDB Query Summary

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.