MongoDB (nonfiction)

From Gnomon Chronicles
Jump to navigation Jump to search

MongoDB (from humongous) is a free and open-source cross-platform document-oriented database.

Classified as a NoSQL database, MongoDB avoids the traditional table-based relational database structure in favor of JSON-like documents with dynamic schemas (it calls the format BSON), making the integration of data in certain types of applications easier and faster.

MongoDB is developed by MongoDB Inc., and is published under a combination of the GNU Affero General Public License and the Apache License.

Miscellaneous notes

Wild card

{ "emailAddress": {'$regex': 'karl'} }

Not Equal query

{ "name" : { $ne: "showcase" } }

Distinct Event Types

db.eventtrackings.distinct( "eventType" )

{"name" : "categorytype-delete"}

insert{"name":"categorytype-delete","description":"the ability to delete a category"}

db.aclpermissions.insert ({ name : "categorytype-delete", description : "the ability to delete a category" })

db.categorytypes.insert ({ categoryTypeUrl : "kj-test", name : "KJ Test", nameV1: "KJ Test v1", isVisible: true, allowAutoViews: true })

{

   "_id" : ObjectId("574f91b3b55602296def65ab"), 
   "categoryTypeUrl" : "people-dronies", 
   "name" : "People/Dronies", 
   "nameV1" : "People", 
   "isVisible" : true, 
   "allowAutoViews" : true

}

Query by ID

"_id" : ObjectId("5925b7e8987d58186ad49d58")

Case insensitive string query

{"userNameDisplay" : /^asdf$/i}

Sort Order

"$orderby", { age : -1 }

Fields to display

Projection = {_id: 1, videoId: 1, numberOfViewsAdded: 1, numberOfViews: 1} { _id: 1, viewCount: 1, autoViewCount: 1, commentAutoViewSeriesCount: 1, createdDate:1 }

Delete all documents from collection

db.autoviews.deleteMany({})

Date query greater than or equal to ISO date

{createdDate: {"$gte": new ISODate("2017-07-14T16:37:52.013Z")}}

{createdDate: {"$gte": new ISODate("2017-08-01T17:55:44.153Z")}}

{createdDate: {"$gte": new ISODate("2017-08-01T22:43:38.905Z"), "$lt": new ISODate("2017-08-02T00:10:07.811Z") }}

And and Date

{ $and: [ { eventName: /comment-saved/}, { createdDate: { $gte: new ISODate("2017-09-25T01:01:57.583Z") } } ] }

{ $and: [ { eventName: /autoview/}, { createdDate: { $gte: new ISODate("2017-09-05T14:47:57.583Z") } } ] }

Group

Does not work (group by error):

db.eventtrackings.aggregate( [ { $group : { _id : "$error" } } ])

Find Element In Array

{collections: { $in: [ObjectId('5bd320904472cc06dc10809b')] }}

In the News

Fiction cross-reference

Nonfiction cross-reference

External links: