DB.put () विधि PouchDB डेटाबेस में एक Document बनाने के लिए प्रयोग किया जाता है. PouchDB Database में बनाए गए Document को एक Variable में संग्रहीत किया जाता है.
इस System को Parameter के रूप में पास किया जाता है। यह विधि एक Callback Function को Parameter के रूप में भी स्वीकार कर सकता है.
db.put(document, callback)
PouchDB में Put () विधि का उपयोग करके एक Document बनाते हैं.
आप जो Document बनाते हैं वह JSON जैसा होना चाहिए Comma (,) द्वारा अलग-अलग key-value जोड़े का एक सेट और Curly Braces ({}) के अंदर स्थित होना चाहिए.
//Requiring the package
var PouchDB = require('PouchDB');
//Creating the database object
var db = new PouchDB('Second_Database');
//Preparing the document
doc = {
_id : '001',
name: 'Altamas',
age : 28,
designation : 'Developer'
}
//Inserting Document
db.put(doc, function(err, response) {
if (err) {
return console.log(err);
} else {
console.log("Document created Successfully");
}
});
आप अलग रूप से संग्रहीत Database (CouchDB) में एक Document भी Include कर सकते हो. आपको बस Database के Way को पारित करना होगा जहां आप Database नाम के बजाय CouchDB में Documents बनाना चाहते हो.
//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: 'Altamas',
age : 22,
designation : 'Developer'
}
//Inserting Document
db.put(doc, function(err, response) {
if (err) {
return console.log(err);
} else {
console.log("Document created Successfully");
}
});