Giter Club home page Giter Club logo

cordova-mongodb-storage's Introduction

npm npm

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.


Install

To install this plugin run cordova plugin add cordova-mongodb-storage in your projects root folder.

Android

  • Update defaultMinSdkVersion in the build.gradle file to 21 instead of the standard 19.

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 iOS 11.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.


initiate(app-id: string) -> boolean

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.

window.plugins.mongodb.initiate("appId")
.then((result) => {
    console.log(result);
})
.catch((error) => {
    console.error(error);
});

insertOne(database: string, collection: string, document: JSONObject) -> Promise<JSONArray | boolean>

API reference for 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:

window.plugins.mongodb.insertOne('exampleDatabase', 'exampleCollection', {"exampleKey": "exampleValue"})
.then((result) => {
    console.log(result);
})
.catch((error) => {
    console.error(error);
});

findOne(database: string, collection: string, filter: JSONObject) -> Promise<JSONArray | boolean>

API reference for 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:

window.plugins.mongodb.findOne('exampleDatabase', 'exampleCollection', {"exampleKey": "exampleValue"})
.then((result) => {
    console.log(result);
})
.catch((error) => {
    console.error(error);
});

replaceOne(database: string, collection: string, filter: JSONObject, update: JSONObject) -> Promise<boolean>

API reference for 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:

window.plugins.mongodb.replaceOne('exampleDatabase', 'exampleCollection', {"exampleKey": "exampleValue"}, {"exampleKey": "newExampleValue"})
.then((result) => {
    console.log(result);
})
.catch((error) => {
    console.error(error);
});

updateOne(database: string, collection: string, filter: JSONObject, update: JSONObject) -> Promise<boolean>

API reference for 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:

window.plugins.mongodb.updateOne('exampleDatabase', 'exampleCollection', {"exampleKey": "exampleValue"}, {$set: {"exampleKey": "newExampleValue"}})
.then((result) => {
    console.log(result);
})
.catch((error) => {
    console.error(error);
});

updateMany(database: string, collection: string, filter: JSONObject, update: JSONObject) -> Promise<boolean>

API reference for 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:

window.plugins.mongodb.updateMany('exampleDatabase', 'exampleCollection', {"exampleKey": "exampleValue"}, {$set: {"exampleKey": "newExampleValue"}})
.then((result) => {
    console.log(result);
})
.catch((error) => {
    console.error(error);
});

findAll(database: string, collection: string) -> romise<JSONArray>

API reference for find

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.

window.plugins.mongodb.findAll('exampleDatabase', 'exampleCollection')
.then((result) => {
    console.log(result);
})
.catch((error) => {
    console.error(error);
});

deleteOne(database: string, filter: string, filter) -> Promise<JSONArray | boolean>

API reference for 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.

window.plugins.mongodb.deleteOne('exampleDatabase', 'exampleCollection', {"exampleKey": "exampleValue"})
.then((result) => {
    console.log(result);
})
.catch((error) => {
    console.error(error);
});

cordova-mongodb-storage's People

Contributors

dependabot[bot] avatar koenkamman avatar mikakrooswijk avatar pestilho avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

cordova-mongodb-storage's Issues

It is not possible to install this plugin

Describe the bug
I can not install this plugin 'cause it does not have www folder with js file in it.

To Reproduce
Steps to reproduce the behavior:

  1. Try to install it on windows 10

Expected behavior
Installed and working plugin

Screenshots
image

Desktop (please complete the following information):

  • OS: Windows 10
  • Browser: Chrome

Use/support the @hamstudy/mongodb-mobile-client library

I've been working on a capacitor plugin for mongoDB mobile; I used a lot of ideas from your plugin to start with but it's a lot further along now.

https://github.com/HamStudy/capacitor-mongodb-mobile

You are welcome to copy as much of it as is useful wholesale into your app; if you can make an interface which is compatible with mine (https://github.com/HamStudy/capacitor-mongodb-mobile/blob/master/src/sharedDefinitions.ts) then yours would work with the client wrapper I wrote which is 95%+ compatible with the node.js mongodb query drivers

https://github.com/HamStudy/mongodb-mobile-client

I haven't done the Java side yet, that's next on my list. Let me know if I can help or if you want to discuss; I'll try to hang out on the https://getcapacitor.slack.com slack #plugins channel

Swift Compiler Error - Cannot find type 'CDVPlugin' in scope

Describe the bug
Cannot build my current project after I added this plugin to the ios platform.

To Reproduce
Steps to reproduce the behavior:

  1. Open *.xcworkspace with Xcode (12.0.1)
  2. Select build option Any iOS Device (arm64)
  3. Go to poduct > build
  4. See error

Expected behavior
A successful build without any errors.
The next step is to deploy it on a real device. (14.0.1)

Screenshots
The error which occurs on Xcode (12.0.1)
Screenshot 2020-09-28 at 17 26 12

Smartphone (please complete the following information):

  • Device: iPhone XS
  • OS: iOS 14.0.1

Additional context
Plugin Version: 0.0.9

If I missed something, please let me know.

iOS Build fails before Swift Version not set

Describe the bug
When trying to run a build of my iOS app, I get the following error:

[!] Unable to determine Swift version for the following pods:

  • MongoMobile does not specify a Swift version and none of the targets (LetsChat) integrating it have the SWIFT_VERSION attribute set. Please contact the author or set the SWIFT_VERSION attribute in at least one of the targets that integrate this pod.
  • MongoSwift does not specify a Swift version and none of the targets (LetsChat) integrating it have the SWIFT_VERSION attribute set. Please contact the author or set the SWIFT_VERSION attribute in at least one of the targets that integrate this pod.
  • StitchCore does not specify a Swift version and none of the targets (LetsChat) integrating it have the SWIFT_VERSION attribute set. Please contact the author or set the SWIFT_VERSION attribute in at least one of the targets that integrate this pod.
  • StitchCoreLocalMongoDBService does not specify a Swift version and none of the targets (LetsChat) integrating it have the SWIFT_VERSION attribute set. Please contact the author or set the SWIFT_VERSION attribute in at least one of the targets that integrate this pod.

To Reproduce
Steps to reproduce the behavior:

  1. Add this plugin to a project
  2. Try to run an iOS build

Expected behavior
It would install everything correctly, without errors.

Screenshots

** Plugins **
cordova-android-play-services-gradle-release
cordova-android-firebase-gradle-release
cordova-custom-config
cordova-plugin-wkwebview-engine
cordova-plugin-whitelist
cordova-plugin-device
cordova-mongodb-storage
cordova-plugin-cocoapod-support
cordova-plugin-add-swift-support

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.