Mongodb

Tools

VSCode: cosmoDB https://code.visualstudio.com/docs/azure/mongodb

MongoDBCompass (cannot insert command)

Robot3T

Getting Started

Installation ( For MAC)

install environment

install driver

npm install --save mongodb

Initial Code

Use option upsert is convenient for achieving insertOrUpdate mechanism.

Cursor

avoid calling findOne multiple time, use Cursor.each instead.

Reference

http://mongodb.github.io/node-mongodb-native/2.2/quick-start/quick-start/

Shard

  • How to specify Shared Key

    • Range

      • Increase opportunity to find thhe single Shard that holds the required dataset.

    • Hashed

      • Needs to scatter the queries to all shards and find the dataset

Schema Design

Mongoose

  • Plugins

  • Schema

    • Model is useful when scale out the applications

  • Populate

    • Get the reference content by populate the field of reference Id

    • Or can use dynamic reference type to reference content in runtime,

    • the Calendar Model contains field of reference

    ```

CalendarEvent.find(deviceEventQuery).populate("reference");

eventType: { type: String, required: true, enum: EVENT_TYPES }, title: { type: String, required: true }, reference: { type: ObjectId, //reference to Device / PlayList EventSchema required: true, refPath: "eventType" }, ```

  • Operators $in, $gte, $lte, $gt, $lt, $contains $nin

https://docs.mongodb.com/manual/reference/database-profiler/

Performance

keyExamined less than nreturned

https://docs.mongodb.com/v3.4/reference/database-profiler/

Concurrency

Error

VersionError

Last updated

Was this helpful?