/    Sign up×
Community /Pin to ProfileBookmark

I saw job offets vor javascriptdevelopers in London Well paid
It was mentioned thath the knowledge of MongoDBNode is advisable almost required:

As My tactics to remember better and spread my activity through internet which gives enromous power I retyped Mongo Db researching the book more I notice there is also possibilty to remove the data and others:

As long as I undertsand the database allows to sort, search the data, text at some points:

ownload the mongo http://www.mongodb.org/downloads
Or in Windows, run the .exe file from the command prompt:
c:mongodbbinmongod.exe

  • The MongoDb Native Node.js Driver
    Mongoose
  • npm install mongodb

    Creatinmg database:
    var mongodb = require (‘mongodb’);

    Then create a new database :

    var dbServer = new mongodb.Server(‘localhost’, 27017, {auto_reconnect:
    true]),
    var db = new mongodb.Db (;mydb;, dbServer, {w: 1 });
    creating collections:
    db.open(function(err, conn) {

    });

    Adding a collection

    adding collection to the database

    db.open( function(err, conn) {
    // add a collection to the db
    db.collection(‘myCollection’, function(err, collection) {
    // insert a document into the collection
    collection. insert( {
    a: ‘my item’
    }, function (err, result) {
    // log the result
    console.log(result);

    // close the connection
    db.close();
    });
    });
    });

    After that run the script in node
    Poicture shiws the database and collection created

    Reading data
    After adding documents to the database you can read them using find()
    But before using the find() API create a new collection to work with :

    // open database connection
    db.open ( function(err, conn) {
    // selet the collection
    db. collection(‘MyNewCollection’, function(err, collection) {
    // cache a count variable
    var count = 0;

    // insert numbers into the collection
    for (var i = 0; i <5; i++ ) {
    collection. insert ({
    num: i
    }, function (err, result) {
    // log the result
    console.log(result);

    // increment the count value
    count ++;

    // if the count is high enough, close the connection
    if ( count > 4 ) {
    db.close();
    }
    });
    }

    });
    });

    Select all Entries in a collection
    Now that a collection has been created you can select all the data in the database :

    db.open ( function (err, conn) {
    / select the collection
    db. collection(‘myNewCollection’, function(err, collection) {
    // select all the documents in the collection
    collection.find().toArray(function(err, result) {
    // log the data
    console.log(result);

    //close the connection
    db.close();
    });
    });

    });

    Select Specific Entries:

    db.collection(‘myNewCollection’,function(err, collection) {
    // select all documents where num is 2
    collection.find ({num: 2 }).toArray(function(err, result) {
    //log the data
    console.log(result);

    //close the connection
    db.close();
    });
    });
    More advances Query selectors:

    //select the collection
    db.collection(‘MyNewCollection’, function(err, collection) {
    // select numbers greater than 1
    collection.find({num: {$gt:1}}).toArray(function(err, result) {
    //log the data
    console.log(result);

    // close the connection
    db.close();

    });
    });

    You can combine additional parameters in the query object. For instance, you can matcg all tge values that are greater than 1 but also less than 1
    db.collection(‘myNewCollection’, function(err, collection) {
    // select numbers greater than 1 but less than 4
    collection. find({num: {$gt: 1, $lt: 4 }}).toArray(function(err, result) {
    // log the data
    console.log(result);

    // close the connection
    db.close();
    });
    })
    ;

    You can also limit the number of documents the search returns:
    db.collection(‘myNewCollection’, function(err, collection) {
    // select all the data in the collection, limited to 3 entries
    collection.find({}, {limit: 3 }) .toArray(function(err, result) {
    // log the data
    console.log(result);

    // close the connection
    db.close();

    });
    });

    Additionally, you can sort the documents in the collection when selectin them

    db.collection(‘myNewCollection’, function(err, colection) {
    //sort the collection in reverese order
    collection.find{}, {sort:[{‘num’, ‘desc’]]}). toArray(function(err, result) {
    // log the data
    console.log(result);

    // close the connection
    db.close();

    });
    });

    to post a comment
    Full-stack DeveloperJavaScript

    23 Comments(s)

    Copy linkTweet thisAlerts:
    @michaelbezosauthorJun 23.2019 — I plan to spread the mongo db as I know there are good paid jobs for the people with the knowledge of mongo.
    Copy linkTweet thisAlerts:
    @michaelbezosauthorJun 24.2019 — I made picture of turning on mongo but I cannot added this through phone but I can pu on the internet or youtube.
    Copy linkTweet thisAlerts:
    @michaelbezosauthorJun 24.2019 — Crud with MongoDb

    Adding a collection

    db.open{ function{err, conn) {

    // add a collection to the db

    db.collection ('myCollectiom', function (err, collection ) {

    // insert a document into the collection

    collection.insert ((

    a: 'my item'

    }, function(err, result) {

    // log the result

    console.log(result);

    // close the connection
    db.close();
    });

    });

    });

    Reading data:

    // open database connection

    db.open( function(err, conn) {

    // select the collection

    db.collection('myNewCollection', function(err, collection) {

    // cache a count variable

    var count= 0;

    // insert numbers into the collection

    for (var i= 0; i < 5; i++ ) {

    collection.insert ({

    num: i

    }, function (err, result) {

    // log the result

    console.log(result);

    // increment the count vavle
    count++;

    // increment the count value
    count++;

    // if the count is high enough, close the connection
    if ( count > 4 ) {
    db.close();
    }
    });
    }
    });

    });

    Selectric All Entries in A Collection


    Copy linkTweet thisAlerts:
    @michaelbezosauthorJun 24.2019 — More Advanced Query Selectors:

    // select the collection

    db.collection('myNewCollection', function(err, collection) {

    // select numbers greater than 1

    collection.find({ num: {$gt: 1 }}) .toArray(function(err, result ) {

    // log the data

    console.log(result);

    // close the connection
    db.close();

    });

    });



    you can combine additional parameters in the query object, ($gt: 1}, for the num value to match against, which selects all values

    that are greater than 1, as shown in the outpu:

    [{ num:2

    Limiting Entries

    db.collection('MyNewCollection', function(err, collection) {

    // select all the data in the collection, limited to 3 entries

    collection.find({}, {limit: 3}) .toArray(function(err, result) {

    // log the data

    console.log(result);

    // close the connection

    db.close();

    Here the scr

    });

    });
    Copy linkTweet thisAlerts:
    @michaelbezosauthorJun 25.2019 — orting Entries

    db.collection('myNewCollection', function(err, collection) {

    // sort the collection in reverse order

    collection.find({}, {sort:[('num', 'desc']]}).toArray(function(err,

    result) {

    // log the data

    console.log(result);

    // close the connection
    db.close();

    });

    });

    Updating Data:

    db.collection('myNewCollection', function(err, collection) {

    // update one of the documents

    collection.update ({num: 2}, {num: 10}, {safe: true}, function(err) {

    it(err) {

    console.log(err);

    }

    else {

    console.log('Successfully updated');

    }

    db.close({});

    });

    });

    Upserting:

    db.collection('myNewCollection', function(err, collection) {

    // upsert one of the documents

    collection.update({num: 8), {num: 7 }, {safe: true,upsert: true}.

    function(err) {

    if (err) {

    console.log(err);

    }

    else {

    console.log('Successfully updated');

    }

    db.close({});
    });

    });



    Copy linkTweet thisAlerts:
    @michaelbezosauthorJun 25.2019 — Setting a Partucular Field:

    db.collection('myNewCollection' , function(err, collection) {

    // set an individual field

    collection.update({num: 3), ($set: {$set: {desc: 'favorite number' }}, {safe:

    true}, fuction(err) {

    if (err) {

    console.log(err);

    }

    else {

    console.log('Successfully updated');

    }

    db.close({});
    });

    });

    Find and Modify

    db.collection ('myNewCollection', function(err, collection) {

    // find and modify collection.findAndModify((num: 4}, [['_id', 'asc']], {num: 25}. {safe: true}

    , function(err, result) {

    if (err) {
    Copy linkTweet thisAlerts:
    @VITSUSAJun 25.2019 — What do you want to ask?
    Copy linkTweet thisAlerts:
    @michaelbezosauthorJun 29.2019 — I wish to dinf job as the javascript developer in London I hope publishing these articles with be advisable.

    I found lots of jobs like mongo /node library javascript developers but beside the drafts here I did not programm properlly the phones or I did not proceeded making chat Please help me to do it as I reckon retyping the mongo library and node will bring me closer to job as the javascript developer and adapt bigger salary
    Copy linkTweet thisAlerts:
    @michaelbezosauthorJun 30.2019 — It is good idea if I improve my cv particullarly for javascript developers but here is contiunation:

    console.log(err);

    }

    db.close{()};
    });

    });

    Removing documents:

    first you can delete documents from a collection using remove().remove() is pretty straighforward; you just pass in the criteria of the

    documents you want to remove followed by callback

    db.collection('myNewCollection' , function(err, collection ) {

    // remove a document

    collection.remove({num: 1,}, function(err) {

    if (err) {

    console.log(err);

    }

    else {

    console.log('Successfully removed');

    }

    db.close({});
    });

    });

    if you want to do anything with the entry you re removing use find and remove(), However be careful-just

    like witg findAndModify , a sort argument has been added to the api.

    db.collection('myNewCollection', function(err, collection) {

    // find and remove

    collection. findandRemove({num: 0}, [('_id', 'asc']], function(err,

    result) {

    if (err) {

    console.log(err);

    }

    // log the affected document
    else {
    console.log (result);
    }

    db.close ({});
    });

    });

    dropping collections:

    you can also delete an entire collection.To do so, use db.dropCollection():

    // open database connection

    db.open ( function(err, conn) {

    // drop a collection

    db.dropCollection('myNewCollection', function(err, result) {

    if (err) {

    console.log(err);

    }

    else {

    console.log(result);

    }

    db.close();
    });
    });
    Copy linkTweet thisAlerts:
    @michaelbezosauthorJul 02.2019 — After watching again the motivation movies of Elon Musk and Larry Ellison (Java, javasctiprt Oracle foundator) I plan to do simmilar and publish workoholic ideas publishing more javascript code which will provide me to mine publishing of first games, phone programs, chats and all in all in the well paid job in London or other good place as it is obvious computer and space programs rules.
    Copy linkTweet thisAlerts:
    @michaelbezosauthorJul 02.2019 — I plan copy Elon Musks workoholic ideas and his night programming activity and tesla failure programms which gave him and other companies fame and wealth.
    Copy linkTweet thisAlerts:
    @michaelbezosauthorJul 02.2019 — tesla failure programme mean that elon musk worked 100 hours a week for 5 years not having profit from the tesla and all in all ends up in the beautful, strong ,famous company. I would to boost and worth mention the elon musks 100 milion dollar failure at 3 not successful rocket propulsion (I would add larry elisson 480 million dollar failure as well as confidence booster)
    Copy linkTweet thisAlerts:
    @michaelbezosauthorJul 03.2019 — Mongoose

    mongoose is an object modelling tool that connects mongodb for node.

    you are already familair with using backbone so using mongoose will be a piecoe of cake.

    This section teaches you how to install mongoose and create models for store data. you will learn

    the techniques for reading the data to select speciifc documents and fields for those docuemts .

    callback installing the mongoose must be set up manually

    // connect to a MongoDB database

    mongoose.connect ('localhost', 'test');

    // database connection

    var db = mongoose.connection

    // error callback

    db.on('error' , function(msg) {

    console.log(

    'Connection Error: %s', msg

    };

    });
    Copy linkTweet thisAlerts:
    @michaelbezosauthorJul 03.2019 — Opening node https://www.youtube.com/watch?v=5OX0aRcIjc4 and showing the importance of mongoose
    Copy linkTweet thisAlerts:
    @michaelbezosauthorJul 05.2019 — Plan to continue
    Copy linkTweet thisAlerts:
    @michaelbezosauthorJul 05.2019 — AS observing your totally lack of counsiousness and any advice because you are lazy I realised one way of implementing the conde would be write the above mentioned commands in the the screen of mongoose and other tools. I downloaded today mongoose from the irish website.

    I am at the stage of creating the schema for different types of fruit . I will implement the code into the mos tool or mos window but If would be good if any of the forum developer could direct me at any constructive way not only watching because I am not yet Zuckuber, Bezos or Gates . or other kings of the code.
    Copy linkTweet thisAlerts:
    @michaelbezosauthorJul 05.2019 — mogoose tool looks good it looks like this

    https://www.youtube.com/watch?v=Qqy4R5nTo4E

    I think I can start copying the command and see the result
    Copy linkTweet thisAlerts:
    @michaelbezosauthorJul 05.2019 — Mongoose

    mongoose is an object modelling tool that connects mongodb for node.

    you are already familair with using backbone so using mongoose will be a piecoe of cake.

    This section teaches you how to install mongoose and create models for store data. you will learn

    the techniques for reading the data to select speciifc documents and fields for those docuemts .

    callback installing the mongoose must be set up manually

    // connect to a MongoDB database

    mongoose.connect ('localhost', 'test');

    // database connection

    var db = mongoose.connection

    // error callback

    db.on('error' , function(msg) {

    console.log(

    'Connection Error: %s', msg

    };

    });

    // success callback

    db.once('open' , function callback () {

    // on success

    console.log('Database opened successfully');

    });

    Copy linkTweet thisAlerts:
    @michaelbezosauthorJul 05.2019 — 
    You use the models to define all the documents in Mongoose. Models Allow you to abstract away the database system and

    focus on what you really want the data. In thios section you learn

    how to create a schena to defibe the structure of a model and then create and save models accoridng to that strucutre

    Creating Schema

    Creating schema for different types of a fruit:

    // define the schema

    var fruitSchema = mongoose.Schema({

    name: String,

    color: String,

    quantity: Number,

    ripe: Boolean

    });

    Creating a Model

    //define the model

    var Fruit =mongoose.model('fruit', fruitSchema);

    After creating the strucutre, create a new instance of the model

    // create a new instance of the model
    Copy linkTweet thisAlerts:
    @michaelbezosauthorJul 05.2019 — https://www.youtube.com/watch?v=B8qxS5c5xas help, help
    Copy linkTweet thisAlerts:
    @michaelbezosauthorJul 05.2019 — https://www.youtube.com/watch?v=slALIKsvNIQ
    Copy linkTweet thisAlerts:
    @michaelbezosauthorJul 05.2019 — https://www.youtube.com/watch?v=SjMWFsF_LVE mongoose development
    ×

    Success!

    Help @michaelbezos spread the word by sharing this article on Twitter...

    Tweet This
    Sign in
    Forgot password?
    Sign in with TwitchSign in with GithubCreate Account
    about: ({
    version: 0.1.9 BETA 5.5,
    whats_new: community page,
    up_next: more Davinci•003 tasks,
    coming_soon: events calendar,
    social: @webDeveloperHQ
    });

    legal: ({
    terms: of use,
    privacy: policy
    });
    changelog: (
    version: 0.1.9,
    notes: added community page

    version: 0.1.8,
    notes: added Davinci•003

    version: 0.1.7,
    notes: upvote answers to bounties

    version: 0.1.6,
    notes: article editor refresh
    )...
    recent_tips: (
    tipper: @Yussuf4331,
    tipped: article
    amount: 1000 SATS,

    tipper: @darkwebsites540,
    tipped: article
    amount: 10 SATS,

    tipper: @Samric24,
    tipped: article
    amount: 1000 SATS,
    )...