S
S
SideWest2019-10-26 20:40:39
MongoDB
SideWest, 2019-10-26 20:40:39

How to work with this mongo db?

RESOLVED! I'M A FOOL! IT IS NECESSARY ON THE SITE TO ALLOW ALL IP TO CONNECT!
I really ask for your help, all day of flour I
started mastering Mongo, found Mongoose, it seems clear, I created a console application that accesses my cluster on the mongo website, so I decided to transfer it to a Linux server, flew

[Mongo Driver Error]:Timed out after 10000 ms while waiting to connect.

I searched for half a day, no one knows, I think okay, I'll use the official one
npm i mongodb

I read the third hour the documentation. I can’t understand anything, I understand that I’m stupid, but I beg you, just write how to finally use this horror
const MongoClient = require('mongodb').MongoClient;
const url = 'mongodb+srv://meow:ПАРОЛЬ@meow-ix3up.mongodb.net/test?retryWrites=true&w=majority';
const dbName = 'test';
const client = new MongoClient(url, { useNewUrlParser: true,useUnifiedTopology: true });
const db = client.db(dbName);
const collection = db.collection('uzvers');

db.uzvers.insertOne({1:'meow'})

This thing should insert a small json into the "test" database, into the "uzvers" table
Please explain to me as a simple person what to write so that it just works and I can do insert, replace and that's it
5db48513dd294599926338.png

Answer the question

In order to leave comments, you need to log in

2 answer(s)
H
h88p, 2019-10-27
@SideWest

Use mongoose
Connection

const mongoose = require('mongoose');
const url = 'mongodb+srv://meow:ПАРОЛЬ@meow-ix3up.mongodb.net/test?retryWrites=true&w=majority';
mongoose.connect(url, { useNewUrlParser: true, useUnifiedTopology: true });

Create a new model in the uzvers.js file
const mongoose = require('mongoose');
const { Schema } = require('mongoose');

const Uzver = new Schema(
    { 
        sho: String
    }
)

const Uzvers = mongoose.model('Uzvers', Uzver);
module.exports = {
    Uzvers
};

Insert new entries in server.js
const { Uzvers }      = require('./uzvers');
const uzver = new Uzvers({
    sho: 'Meow'
});
uzver.save().then(() => 'Сохранено');

I
index0h, 2019-10-26
@index0h

The simplest thing is to raise the mongo locally and play with it

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question