You can make an archive in PouchDB utilizing the db.put() technique.
Syntax
Following is the sentence structure of utilizing the db.put() strategy for PouchDB. You can store the archive that will be made in PouchDB, in a variable and pass as a boundary to this technique. Moreover, this technique likewise acknowledges a callback (discretionary) work as a boundary.
db.put(document, callback)
Example
Following is an illustration of making a report in PouchDB utilizing the put() technique. The report we make ought to be of JSON design, a bunch of key-esteem sets isolated by comma (,) and encased inside wavy supports ({}).
//Requiring the package
var PouchDB = require('PouchDB');
//Creating the database object
var db = new PouchDB('my_database');
//Preparing the document
doc = {
_id : '001',
name: 'Raju',
age : 23,
designation : 'Designer'
}
//Inserting Document
db.put(doc, function(err, response) {
if (err) {
return console.log(err);
} else {
console.log("Document created Successfully");
}
})
Save the above code in a record with name Create_Document.js. Open the order provoke and execute the JavaScript record utilizing hub as demonstrated beneath.
C:\PouchDB_Examples >node Create_Document.js
This makes the given report in PouchDB information base named my_database, which is put away locally, showing the accompanying message.
Document created Successfully
Inserting a Document in a Remote Database
You can likewise embed a report in the information base that is put away distantly on the worker (CouchDB).
To do as such, rather than data set name you need to pass the way to the data set where you need to make records in CouchDB.
Example
Assume there is a data set named my_database in the CouchDB worker. At that point, on the off chance that you check the rundown of information bases in CouchDB utilizing the URL http://127.0.0.1:5984/_utils/index.html you will get the accompanying screen capture.
Presently, in the event that you click on the data set named my_database, you will locate a vacant information base as demonstrated in the accompanying screen capture.
Following is an illustration of embeddings an archive in an information base named my_database that is saved in the CouchDB worker.
//Requiring the package
var PouchDB = require('PouchDB');
//Creating the database object
var db = new PouchDB('http://localhost:5984/my_database');
//Preparing the document
doc = {
_id : '001',
name: 'Raju',
age : 23,
designation : 'Designer'
}
//Inserting Document
db.put(doc, function(err, response) {
if (err) {
return console.log(err);
} else {
console.log("Document created Successfully");
}
});
Save the above code in a document with the name Remote_Create_Document.js. Open the order provoke and execute the JavaScript record utilizing hub as demonstrated underneath.
C:\PouchDB_Examples >node Remote_Create_Document.js
This makes the given report in PouchDB data set named my_database which is put away in CouchDB, showing the accompanying message.
Document created Successfully
Verification
In the wake of executing the above program, on the off chance that you visit the my_database once more, you can notice the record made as demonstrated in the accompanying screen capture.