cordova-mongodb-storage
This is a Cordova plugin that exposes the functionality of MongoDB Mobile to a Cordova Android or iOS app for local storage.
NPM
Install
To install this plugin run cordova plugin add cordova-mongodb-storage
in your projects root folder.
Android
- Update
defaultMinSdkVersion
in thebuild.gradle
file to21
instead of the standard19
.
iOS
- Run pod install in iOS folder of your project. For more information on cocoapods please look here.
- Be sure to set the
Deployment Target
to at least iOS11.0
in your.xcodeproj
file.
Functionality
This is the functionality the plugin provides right now, it is limited but provides the basic CRUD functionality. More will be added in the future.
app-id: string
) -> boolean
initiate(This function has to be called before doing anything else with the plugin.
app-id
the id of this app.
returns
true if the initiation was successful, false if it failed.
windowpluginsmongodb;
database: string
, collection: string
, document: JSONObject
) -> Promise<JSONArray | boolean>
insertOne(
database
the database that is to be queried.
collection
the collection that is to be queried
document
a JSON object that is to be inserted into the database.
returns
A promsie that resolves to a JSONArray containing the inserted document, false if the insert failed.
Example usage:
windowpluginsmongodb;
database: string
, collection: string
, filter: JSONObject
) -> Promise<JSONArray | boolean>
findOne(
database
the database that is to be queried.
collection
the collection that is to be queried
filter
a JSON object that provides the filter for the query.
returns
A promsie that resolves to a JSONArray containing the first document that was found matching the filter, or false if there was no document found matching the filter.
Example usage:
windowpluginsmongodb;
database: string
, collection: string
, filter: JSONObject
, update: JSONObject
) -> Promise<boolean>
replaceOne(
database
the database that is to be queried.
collection
the collection that is to be queried
filter
a JSON object that provides the filter for the replace.
update
the object that is to be updates or inserted.
returns
A promsie that resolves to totrue when the replace was successful, and to false when it failed.
! upsert is set to true for this function.
Example usage:
windowpluginsmongodb;
database: string
, collection: string
, filter: JSONObject
, update: JSONObject
) -> Promise<boolean>
updateOne(
database
the database that is to be queried.
collection
the collection that is to be queried
filter
a JSON object that provides the filter for the update.
update
the update to be made.
returns
A promsie that resolves to totrue when the update was successful, and to false when it failed.
In the update object be sure to use the Update operators, such as $set
and $rename
Example usage:
windowpluginsmongodb;
database: string
, collection: string
, filter: JSONObject
, update: JSONObject
) -> Promise<boolean>
updateMany(
database
the database that is to be queried.
collection
the collection that is to be queried
filter
a JSON object that provides the filter for the update.
update
the updates to be made
returns
A promsie that resolves to totrue when the update was successful, and to false when it failed.
In the update object be sure to use the Update operators, such as $set
and $rename
Example usage:
windowpluginsmongodb;
database: string
, collection: string
) -> romise<JSONArray>
findAll(
Returns all the entries is a given database and collection.
database
the database that is to be queried.
collection
the collection that is to be queried
returns
A promsie that resolves to a JSONArray with all the documents in the specified database and collection.
windowpluginsmongodb;
database: string
, filter: string
, filter
) -> Promise<JSONArray | boolean>
deleteOne(
database
the database that is to be queried.
collection
the collection that is to be queried
filter
the filter for the document to be deleted
returns
A promsie that resolves to a JSONArray containing the document deleted, false if there was no document found matching the filter.
windowpluginsmongodb;