Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

How to access a preexisting collection with Mongoose?

const mongoose = require("mongoose");
mongoose.connect('mongodb://localhost/productsDB');

const connection = mongoose.connection;

connection.on('error', console.error.bind(console, 'connection error:'));
connection.once('open', async function () {

  const collection  = connection.db.collection("Products");
  collection.find({}).toArray(function(err, data){
      console.log(data); // it will print your collection data
  });

});
Comment

How to access a preexisting collection with Mongoose

new Schema({ url: String, text: String, id: Number}, 
       { collection : 'question' });   // collection name
Comment

PREVIOUS NEXT
Code Example
Javascript :: Node.js with Express: Importing client-side javascript using script tags in Jade views 
Javascript :: Using javascript code in Jade views - if(variable) shows undefined instead of passing 
Javascript :: p5 filter 
Javascript :: yaml request body json 
Javascript :: select the value of dropdownMenu with Semantic ui react 
Javascript :: javascript check if key is keydown is charcter 
Javascript :: No enum constant datepicker react native 
Javascript :: cleave js 
Javascript :: nodejs passport starter template with username and password 
Javascript :: react state based router 
Javascript :: ... Notation In JavaScript 
Javascript :: JSON Using Its Own Property To Get Promise Value 
Javascript :: convert json date to java date 
Javascript :: javascript cookies all together 
Javascript :: Declaring A Internal Method Of A Class 
Javascript :: maptable elo 
Javascript :: css to jss 
Javascript :: como hacer un contador de tiempo en javascript 
Javascript :: CUSTOM_ELEMENTS_SCHEMA 
Javascript :: add text to each element in an array javascript 
Javascript :: how to check bot channel permissions 
Javascript :: pnpm tailwind react 
Javascript :: how to create existing nodes in godot 
Javascript :: Backbone Add To Collection 
Javascript :: screen orientation and width&height 
Javascript :: get user badge discordjs 
Javascript :: convert milliseconds to dd/mm/yyyy javascript 
Javascript :: router.push 
Javascript :: 206. reverse linked list javascript 
Javascript :: events node.js 
ADD CONTENT
Topic
Content
Source link
Name
1+5 =