mongodb-expressions

MongoDB expressions for fire.js

#mongodb-expressions

The official MongoDB expressions for fire.js


Inserts a document in a MongoDB collection given in the hint. Returns the same document with the generated _id.

This example inserts a contact document into the contacts collection:

{
    "@Mongo.Insert(contacts)": {
        email: "johan@firebase.co"
        firstName: "Johan",
        lastName: "Hernandez"
    }
}

When you call Mongo.Insert you need to provide the name of the collection you want to insert to.

The input is an array, you can't insert arrays. It must be an object.

The input is null. You can't insert null into a collection.

The input is anything but an object. Numbers, Functions, Strings can not be inserted directly into a collection.

Retrieve documents from a collection given in the hint. Returns an array of matched documents by the criteria. If the input is null or @undefined or you don't provide a condition it will retrieve all the documents in the collection.

Mongo.Find accepts an input with the following attributes:

{
    "conditions": <object, optional>,
    "fields": <array, optional>,
    "sort": <object, optional>,
    "limit": <Number, optional>,
    "skip": <Number, optional>
}

An object with all the conditions to be used as criteria. More info about MongoDB Queries.

An array with all the fields names to include in the results. It supports dot notation so you can specify the embedded documents fields too.

An object with all the sorting options. More info here and here

It specifies a maximum number of results to return. More info.

It specifies at which object the database should begin returning results More info

When you call Mongo.Find you need to provide the name of the collection you want to query from.

When you call Mongo.Find you can't use includingFields and excludingFields options at the same time, you can either use one of them or none of them.

Retrieve a single document from a collection given in the hint matched by criteria. If no document can be matched with by the criteria it will return null. If the input is null or @undefined or you don't provide a condition it will retrieve the first document in the collection.

Mongo.FindOne accepts an input with the following attributes:

{
    "conditions": <object, optional>,
    "fields": <array, optional>,
    "sort": <object, optional>,
    "skip": <Number, optional>
}

An object with all the conditions to be used as criteria. More info about MongoDB Queries.

An array with all the fields names to include in the results. It supports dot notation so you can specify the embedded documents fields too.

An object with all the sorting options. More info here and here

It specifies at which object the database should begin returning results More info

Same errors and solutions than @Mongo.Find

Updates documents from a collection given in the hint. Returns the count of affected rows. All updates are strict and will return either an error if they fail or the count of update rows if succeeded.

Mongo.Update accepts an input with the following attributes:

{
    "conditions": <object>,
    "changes": <object>,
    "options": <object, optional>,
}

An object with all the conditions to be used as criteria. More info about MongoDB Queries.

An object with all the changes to perform. More info about MongoDB udpates

It specifies the options to use when updating. The more common options are multi and upsert.

When set to true all matching documents are updated, not just the first.

When set to true Atomically inserts the document if no documents matched.

When you call Mongo.Update you need to provide the name of the collection you want to update.

Remove documents from a collection given in the hint. Returns the count of affected rows. All updates are strict and will return either an error if they fail or the count of removed rows if succeeded.

Mongo.Remove accepts an input with a single attribute:

{
    "conditions": <object>
}

An object with all the conditions to be used as criteria when removing the documents. More info about MongoDB Queries.

When you call Mongo.Remove you need to provide the name of the collection you want to remove documents from.

Drops the current database.

mongodb-expressions will automatically execute @Mongo.DropDatabase when the runtime is loaded in NODE_ENV test.

git clone https://github.com/firebaseco/mongodb-expressions.git
make
  • Johan (author). Email: johan@firebase.co

Copyright (c) 2011 Firebase.co - http://www.firebase.co

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.