nativescript-mongo-stitch-core
nativescript-mongo-stitch-sdk
nativescript-mongo-stitch-services-mongodb-remote
Note Android min-sdk is 21 & Note IOS min platform is 11
tns plugin add nativescript-mongo-stitch-sdk
import {
Stitch
} from 'nativescript-mongo-stitch-sdk';
Stitch.initializeDefaultAppClient('<your-client-app-id>').then(client => {
// use the client
});
import {
AnonymousCredential,
Stitch
} from 'nativescript-mongo-stitch-sdk';
const client = Stitch.defaultAppClient;
console.log("logging in anonymously");
client.auth.loginWithCredential(new AnonymousCredential()).then(user => {
console.log(`logged in anonymously as user ${user.id}`)
});
import {
Stitch,
RemoteInsertOneResult,
RemoteMongoClient,
AnonymousCredential,
Bson
} from 'nativescript-mongo-stitch-sdk';
let remoteClient;
Stitch.initializeAppClient('<your-client-app-id>').then(client => {
console.log(client.auth.isLoggedIn);
this.client = client;
return this.client.auth.loginWithCredential(new AnonymousCredential());
}).then(user => {
this.user = user;
console.log('loggedIn as', user.id);
remoteClient = this.client.getServiceClient(RemoteMongoClient.factory, 'mongo-atlas-test');
remoteClient
.db('tns-test')
.collection('mobile-test')
.insertOne({
'first': 'Osei', 'last': 'Fortune', 'owner_id': this.user.id,
'rand_id': Bson.ObjectId(this.user.id),
'ts': Date.now(),
})
.then((result: RemoteInsertOneResult) => {
console.log(result.insertedId);
}).catch(error => {
console.error('insert error', error);
});
}).catch(error => {
console.log(error);
});
import {
Stitch,
LocalInsertOneResult
} from 'nativescript-mongo-stitch-sdk';
import {
Stitch,
LocalInsertOneResult,
LocalMongoClient,
AnonymousCredential,
Bson
} from 'nativescript-mongo-stitch-sdk';
let remoteClient;
Stitch.initializeAppClient('<your-client-app-id>').then(client => {
console.log(client.auth.isLoggedIn);
this.client = client;
return this.client.auth.loginWithCredential(new AnonymousCredential());
}).then(user => {
this.user = user;
console.log('loggedIn as', user.id);
remoteClient = this.client.getServiceClient(LocalMongoClient.factory);
remoteClient
.db('tns-test')
.collection('mobile-test')
.insertOne({
'first': 'Osei', 'last': 'Fortune', 'owner_id': this.user.id,
'rand_id': Bson.ObjectId(this.user.id),
'ts': Date.now(),
})
.then((result: LocalInsertOneResult) => {
console.log(result.insertedId);
}).catch(error => {
console.error('insert error', error);
});
}).catch(error => {
console.log(error);
});
Apache License Version 2.0, January 2004