const mongodb = require('mongodb').MongoClient;
const mongoose = require('mongoose');
const puppySchema = new mongoose.Schema({
name: {
type: String,
required: true
},
age: Number
});
const Puppy = mongoose.model('Puppy', puppySchema);
const kittySchema = new mongoose.Schema({
name: String
});
kittySchema.methods.speak = function speak() {
const greeting = this.name
? 'Meow name is ' + this.name
: 'I don\'t have a name';
console.log(greeting);
};
const Kitten = mongoose.model('Kitten', kittySchema);
const fluffy = new Kitten({ name: 'fluffy' });
fluffy.speak();
// Database Connection
const uri = "mongodb+srv://user:password@cluster0.9qmmvce.mongodb.net/?retryWrites=true&w=majority";
const client = new mongodb(uri, {
useNewUrlParser: true,
useUnifiedTopology: true
});
console.log('Connected to Atlas');
client.connect(err => {
const collection = client.db("test2").collection("devices");
// perform actions on the collection object
fluffy
.save()
then((doc) => {
console.log(doc);
})
.catch((err) => {
console.error(err);
});
const kittens = Kitten.find()
.then((doc) => {
console.log(doc);
})
.catch((err) => {
console.error(err);
});
console.log(kittens);
client.close();
});
It prints âConnected to Atlasâ but nothing happens.
EDIT: I tried on several different machines and still the same. Tried locally and Atlasdb.