Thursday, April 25, 2013

MongoDB Miscellaneous

Querying based on Date & Time
   db.[Colletion].find ({Date:ISODate('2013-04-22T00:00:00Z')})

Equivalent of Oracle's Count function
   db.[Collection].find ({'FieldName':'value').length

Find distinct values of a column, after Querying
   db.[Collection].distinct ('ColumnName', {'SearchColumnName' : 'SearchValue'})

Number of distinct values
   db.[Collection].distinct ('ColumnName').length

Sorting the returned result with pymongo
  db.[Collection].find().sort (
  [
   ("FieldName1", pymongo.DESCENDING),
   ("FieldName2", pymongo.DESCENDING),
   ("FieldName3", pymongo.ASCENDING),
  ])


No comments: