1

I am trying to insert the record into my mongoDB. Here is what I tried:

  $.ajax({
                  type: "POST",
                  url: "http://localhost:28017/messages_sent/better/?doc=",
                  data: {
                        thread_id: event.threadID,
                        message_id: event.messageID,
                        user_email: sdk.User.getEmailAddress(),
              token: token
                    },
                  dataType: "JSON"
                });

          countUsage();
          chrome.storage.sync.set({ "last_tracked_email_date": Date.now() });
          alert("hello");
        }
      });

I am trying to look into the MongoDB, but could not find any thing in the database.
How I can insert the record into MongoDB using javascript and Rest API of MongoDB itself?

7

1 Answer 1

2

After a good discussion, I get to know that you were trying, is to just insert data in Mongo.

And this Mongo's rest API feature only supports retrieving data

from official docs

The mongod process includes a simple REST API as a convenience. With no support for insert, update, or remove operations, it is generally used for monitoring, alert scripts, and administrative tasks.

So, there are many ways you can insert data in Mongo:

  • Using APIs in server side code using any server side lang like Python/java/node
  • Using mongo shell, simple insert
  • using some GUI tool, like robomongo
  • and I'm sure there are more

But in comments, OP wanted some data in Mongo to test functionality, so writing APIs for just inserting is not a great solution.

So, if you just want to insert data and comfortable using CLI, then just go in mongo shell, and insert directly into the collection.

But if not, then Robomongo is very efficient. It's made for adding/removing and other CRUD operations.

Simple steps for using robomongo:

  1. Download from official site and install
  2. Open it and click on connect, add your port (default 28017) and host (localhost)
  3. Now on lhs, click on MongoDB and you should see you dbs in it it, if you've created those.
  4. Then you can see your collections inside it, and just right click and click on insert option and you can add your JSON into it and click save.
  5. That's it, doc is saved in collection. Simple right.
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.