client for data API MongoDB atlas
npm install cs-mongo-data-apiread mongodb offical page documentation for more information
mongo-data-api
``bash`
npm install cs-mongo-data-apiUsage
`ts
import { MongoDataApi } from 'cs-mongo-data-api';
export class MyService extends MongoDataApi {
// define your collection
get user(){ return this.collection
}
const api = new MyService({
apiUrl: process.env.MONGO_API_URL!,
database: process.env.MONGO_DATABASE!,
apiKey: process.env.MONGO_API_KEY!,
dataSource: process.env.MONGO_DATA_SOURCE!,
})
api.user.findOne({ id:'123'})
api.user.insertOne({...})
api.collection
//... bulkFind query
const result = await api.box.bulkFind([
{
collection: 'Box',
key: 'box',
filter: { id: '123' },
},
{
collection: 'User',
key: 'user',
filter: { name: 'lala' },
},
]);
result.getOne
result.getMany
`api.queryApdaterswitch to mongodb node driver
By default it use fetch function to call data api but you can switch to mongodb
node driver by set `
when you create api change apiUrl to mongodb node driver connect urlts
import { mongoDbAdapter } from 'cs-mongo-data-api/lib/mongoDbAdapter';
api.queryApdater = mongoDbAdapter
`
after that all query is same
Tutorial
function code
deploy above code with route /bulkAction
ts
import { MongoDataApi } from 'cs-mongo-data-api';
api.user.bulkWrite([
{
insertOne: {
document: { id: '123', name: 'test' },
},
},{
updateOne: {
filter: { id: '123' },
update: { $set: { name: 'test' } },
},
},
])
``realm-web it can't run on local mongodb