Delete document in MongoDB

Use db.collection.remove() method to delete document in MongoDB. You can define a query to make it delete documents match query. How to define a query click Query document in MongoDB. If you want remove all documents of this collection just use empty query to match all documents. MongoDB will delete all document of this collection.

Query document in MongoDB

In MongoDB db.collection.find() method query documents from the collection. If there is no param in it or passing empty param like this db.collection.find({}) will get all documents in this collection. It is like using select * from table_name in structural database.

Format query result in MongoDB

The default result of querying document in MongoDB is not formatted. But if you query one document by using db.collection.findOne() the result is formatted. Is there any way to format the result of db.collection.find()? Yes, use pretty() append db.collection.find(). Examples are here.

Insert data in MongoDB

We need create table before inserting data into structure database(Mysql, PostgreSQL, Oracle etc.). It is no need to create collection for using MongoDB. The db.collection.insert() method adds new document into database. MongoDB will create collection when it not exist. You can also create collection manually then insert document.

Google "Pure spam" problem

Last week I found my site disappear from Google search result. I tried search "" but nothing there. A day later I received the message from Google Search Console. To my surprise, Google prevented my site because "Pure spam". The whole message is here

MongoDB tutorial

MongoDB is one kind of document-oriented NoSQL database. Open-source, cross-platform and free are the reasons large numbers of development team choose it. In this tutorial I will show you how to use it step by step.

Drop database in MongoDB

Use db.dropDatabase() to delete the current selected database. If no database selected this command will delete the default database test. Before deleting you need show all database. Delete a database command like following.

Display PDF in Spring example

In this tutorial I will show you how to display and download pdf file in Spring(Spring MVC). For quick beginning we use Spring Boot, and for displaying pdf we use jsp as view.(How to use jsp in Spring Boot, click Spring Boot JSP examples).

Javascript timestamp to date format

It is easy to use SimpleDateFormat format date in Java. There is no method in Javascript to format date directly. When we want format date in javascript we have to use Date method to get Day, Month, Year and combine them together manually.

Jquery change element class

We can not change class of element directly. But we can use two steps to change class. Remove old then add new one. Use addClass() function to add a class to each element. If you want add more than one class separating each one with a space. This function won't delete exist class it only append the specified class. Use removeClass() function to remove a class. Same as addClass() use space to separate multiple classes if you need remove more than one class.

Drop collection in MongoDB

Drop collection in MongoDB is easy. Use db.collection_name.drop() to drop the collection. All indexes in this collection will be also removed.

Create collection in MongoDB

You can create collection explicitly or make MongoDB help you create collection automatically. When you create collection manually you can use specific options. You can create a capped collection or create a collection with document validation.

Quickly open cmd with current path in Windows

I don't like command prompt in windows. Linux command line is more power than windows. You can't even use tab to auto-complete the path accurately, especially you install the software in C:\Program Files. But, compare with opening a virtual machine installing software in windows is more convenient. Every time when I need use command prompt in windows I have to do following steps.

Create Database in MongoDB

In MongoDB you do not need create database manually. MongoDB will create a new database if necessory. It is different from structure database. Open Mongo shell and type show dbs can show all database. Now there is only one database (local) in my computer.

Install MongoDB as windows service

In this page I will show you how to install MongoDB in windows as service. Download MongoDB .msi file here and install. I assume that you install it in C:\Program Files\MongoDB. MongoDB will connect C:/data/db as default dbpath, if this directory doesn't exist you have to tell MongoDB the right dbpath. I create two directories for log(D:\mongo_data\log) and database(D:\mongo_data\db).