Security News
Fluent Assertions Faces Backlash After Abandoning Open Source Licensing
Fluent Assertions is facing backlash after dropping the Apache license for a commercial model, leaving users blindsided and questioning contributor rights.
cosmosdb-node
Advanced tools
To get started and use this API, you first have to create a CosmosDB account in the Azure portal. Once this is done, just copy this example to get started:
// Your AccountName, this is part of your endpoint
// (Example: https://my-cosmosdb-account.documents.azure.com" gives "my-cosmosdb-account" as AccountName)
const accountName = "my-cosmosdb-account";
// Find this in the Azure Portal under Keys for your CosmosDB Resource
const primaryKey = '<yourPrimaryKey>';
// Initialize the library and connection
const API = require('./CosmosDB')(accountName, primaryKey);
// An example API call
let database = await API.database.createIfNotExists(databaseName);
For more calls, see below or on: https://docs.microsoft.com/en-us/rest/api/documentdb/
await api.database.get(<dbName>)
{ id: 'testDB',
_rid: 'ogYeAA==',
_self: 'dbs/ogYeAA==/',
_etag: '"00004e00-0000-0000-0000-5ab64e0b0000"',
_colls: 'colls/',
_users: 'users/',
_ts: 1521896971 }
await api.database.create(<dbName>)
{ id: 'testDB',
_rid: 'ogYeAA==',
_self: 'dbs/ogYeAA==/',
_etag: '"00004e00-0000-0000-0000-5ab64e0b0000"',
_colls: 'colls/',
_users: 'users/',
_ts: 1521896971 }
await api.database.list()
{ _rid: '',
Databases:
[ { id: 'testDB',
_rid: 'ogYeAA==',
_self: 'dbs/ogYeAA==/',
_etag: '"00004e00-0000-0000-0000-5ab64e0b0000"',
_colls: 'colls/',
_users: 'users/',
_ts: 1521896971 } ],
_count: 1 }
await api.database.createIfNotExists(<dbName>)
{ id: 'testDB',
_rid: 'ogYeAA==',
_self: 'dbs/ogYeAA==/',
_etag: '"00004e00-0000-0000-0000-5ab64e0b0000"',
_colls: 'colls/',
_users: 'users/',
_ts: 1521896971 }
await api.database.delete(<dbName>)
No response will be returned if successful, only an error will be thrown if problems arise.
await api.collection.get(<dbName>, <collectionName>)
{ id: 'testColl',
indexingPolicy:
{ indexingMode: 'consistent',
automatic: true,
includedPaths: [ [Object] ],
excludedPaths: [] },
_rid: 'ogYeAMaxxwE=',
_ts: 1521896971,
_self: 'dbs/ogYeAA==/colls/ogYeAMaxxwE=/',
_etag: '"00004f00-0000-0000-0000-5ab64e0b0000"',
_docs: 'docs/',
_sprocs: 'sprocs/',
_triggers: 'triggers/',
_udfs: 'udfs/',
_conflicts: 'conflicts/' }
await api.collection.create(<dbName>, <collectionName>)
{ id: 'testColl',
indexingPolicy:
{ indexingMode: 'consistent',
automatic: true,
includedPaths: [ [Object] ],
excludedPaths: [] },
_rid: 'ogYeAMaxxwE=',
_ts: 1521896971,
_self: 'dbs/ogYeAA==/colls/ogYeAMaxxwE=/',
_etag: '"00004f00-0000-0000-0000-5ab64e0b0000"',
_docs: 'docs/',
_sprocs: 'sprocs/',
_triggers: 'triggers/',
_udfs: 'udfs/',
_conflicts: 'conflicts/' }
await api.collection.list(<dbName>)
{ _rid: 'ogYeAA==',
DocumentCollections:
[ { id: 'testColl',
indexingPolicy: [Object],
_rid: 'ogYeAMaxxwE=',
_ts: 1521896971,
_self: 'dbs/ogYeAA==/colls/ogYeAMaxxwE=/',
_etag: '"00004f00-0000-0000-0000-5ab64e0b0000"',
_docs: 'docs/',
_sprocs: 'sprocs/',
_triggers: 'triggers/',
_udfs: 'udfs/',
_conflicts: 'conflicts/' } ],
_count: 1 }
await api.collection.createIfNotExists(<dbName>, <collectionName>)
{ id: 'testColl',
indexingPolicy:
{ indexingMode: 'consistent',
automatic: true,
includedPaths: [ [Object] ],
excludedPaths: [] },
_rid: 'ogYeAMaxxwE=',
_ts: 1521896971,
_self: 'dbs/ogYeAA==/colls/ogYeAMaxxwE=/',
_etag: '"00004f00-0000-0000-0000-5ab64e0b0000"',
_docs: 'docs/',
_sprocs: 'sprocs/',
_triggers: 'triggers/',
_udfs: 'udfs/',
_conflicts: 'conflicts/' }
await api.collection.delete(<dbName>, <collectionName>)
No response will be returned if successful, only an error will be thrown if problems arise.
Truncates the collection.
Note: This will delete and recreate the collection, so the ID will change
await api.collection.truncate(<dbName>, <collectionName>)
No response will be returned if successful, only an error will be thrown if problems arise.
await api.document.get(<dbName>, <collectionName>, <documentId>)
{ id: 'test-doc',
hello: 'world',
obj: { test: 'doc' },
arr: [ 'el1', 'el2' ],
_rid: 'ogYeAMaxxwEBAAAAAAAAAA==',
_self: 'dbs/ogYeAA==/colls/ogYeAMaxxwE=/docs/ogYeAMaxxwEBAAAAAAAAAA==/',
_etag: '"00006a59-0000-0000-0000-5ab64e0c0000"',
_attachments: 'attachments/',
_ts: 1521896972 }
await api.document.create(<dbName>, <collectionName>, <document>)
const newDoc = await api.document.create('testDB', 'testColl', {
id: 'test-doc',
hello: 'world',
obj: {
test: 'doc'
},
arr: [ "el1", "el2" ]
})
{ id: 'test-doc',
hello: 'world',
obj: { test: 'doc' },
arr: [ 'el1', 'el2' ],
_rid: 'ogYeAMaxxwEBAAAAAAAAAA==',
_self: 'dbs/ogYeAA==/colls/ogYeAMaxxwE=/docs/ogYeAMaxxwEBAAAAAAAAAA==/',
_etag: '"00006a59-0000-0000-0000-5ab64e0c0000"',
_attachments: 'attachments/',
_ts: 1521896972 }
await api.document.list(<dbName>, <collectionName>)
{ _rid: 'ogYeAMaxxwE=',
Documents:
[ { id: 'test-doc',
hello: 'world',
obj: [Object],
arr: [Array],
_rid: 'ogYeAMaxxwEBAAAAAAAAAA==',
_self: 'dbs/ogYeAA==/colls/ogYeAMaxxwE=/docs/ogYeAMaxxwEBAAAAAAAAAA==/',
_etag: '"00006a59-0000-0000-0000-5ab64e0c0000"',
_attachments: 'attachments/',
_ts: 1521896972 } ],
_count: 1 }
await api.document.query(<dbName>, <collectionName>, <query>)
const myDoc = await api.document.query('testDB', 'testColl', {
query: `SELECT * FROM ${collectionName} c WHERE c.id = @id`,
parameters: [
{
name: '@id',
value: doc.id
}
]
})
{ _rid: 'oQVCAKobrAE=',
Documents:
[ { id: 'test-doc',
hello: 'world',
obj: [Object],
arr: [Array],
_rid: 'ogYeAMaxxwEBAAAAAAAAAA==',
_self: 'dbs/ogYeAA==/colls/ogYeAMaxxwE=/docs/ogYeAMaxxwEBAAAAAAAAAA==/',
_etag: '"00006a59-0000-0000-0000-5ab64e0c0000"',
_attachments: 'attachments/',
_ts: 1521897637 } ],
_count: 1 }
await api.document.createIfNotExists(<dbName>, <collectionName>, <document>)
const newDoc = await api.document.create('testDB', 'testColl', {
id: 'test-doc',
hello: 'world',
obj: {
test: 'doc'
},
arr: [ "el1", "el2" ]
})
{ id: 'test-doc',
hello: 'world',
obj: { test: 'doc' },
arr: [ 'el1', 'el2' ],
_rid: 'ogYeAMaxxwEBAAAAAAAAAA==',
_self: 'dbs/ogYeAA==/colls/ogYeAMaxxwE=/docs/ogYeAMaxxwEBAAAAAAAAAA==/',
_etag: '"00006a59-0000-0000-0000-5ab64e0c0000"',
_attachments: 'attachments/',
_ts: 1521896972 }
await api.document.delete(<dbName>, <collectionName>, <documentId>)
No response will be returned if successful, only an error will be thrown if problems arise.
FAQs
The Node API for interacting with the CosmosDB REST API
The npm package cosmosdb-node receives a total of 4 weekly downloads. As such, cosmosdb-node popularity was classified as not popular.
We found that cosmosdb-node demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Fluent Assertions is facing backlash after dropping the Apache license for a commercial model, leaving users blindsided and questioning contributor rights.
Research
Security News
Socket researchers uncover the risks of a malicious Python package targeting Discord developers.
Security News
The UK is proposing a bold ban on ransomware payments by public entities to disrupt cybercrime, protect critical services, and lead global cybersecurity efforts.