MongoDB Two main operations: one is query, the other is statistics. For queries, it is primarily the find () method, which is combined with filters to combine multiple query criteria.For statistics, it is mainly aggregate operations, such as group, SUM, AVG, project, match ...Aggregate can be organized into pipeline form, followed by a variety of operations processing.This article is a course note for MongoDB
Directly paste the English text. Poor translation affects readers. The English text is as follows:
Gridfs example
This example shows how to useGridfsTo store large binaryobjects (e.g. Files) in MongoDB.
See also
The API docsGridfs.
See also
This blog postfor some motivation behind this API.Setup
We start by creatingGridfsInstance to use:
>>> from pymongo import C
This is a creation in
Article, where the information may have evolved or changed.
Golang mongodb MgO Insert, query a small example, Golang still give me that feeling, than Nodejs write up comfortable. Package main import ("FMT" "Launchpad.net/mgo" "Launchpad.net/mgo/bson") type Mail struct {Id Bson. ObjectId "_id" Name string Email String} func Main () {//Connect to database session, err: = MgO. Dial ("127.
Label:C # Operations MONGO database Drive with Http://www.oschina.net/p/mongo-csharp-driverC # Driven Basic database connection, adding or deleting operations//Defining objectspublic class person
{public
ObjectId _id;
public string Name {get; set;}
public int Age {get; set;}
public override string ToString ()
{
return string. Format ("id:{0} Name:{1} age:{2}", _id, Name, age);
}
}
To add a reference:Using Mongodb.bson;
Using Mongodb.driver;
Using MongoDB.Driver.Builders;
Using MongoDB.
, anyway, the goods also have a very strong place, the disadvantage is not suitable forDataConsistencyHigh demand, such as financial development. But the advantage iscome on .Summary: This means that node and MongoDB combine to be particularly suitable for a scenario- fast, high -throughput situations. Let's start with the preparatory work: (Take the windows8.1 system environment as an example) 1.node:
Lt ;? Php // use the default port 27017 to connect to the local machine. of course, you can also connect to a remote host such as 192.168.0.4: 27017. if the port is 27017, the port can be omitted $ m = newMongo (); // select the comedy Database. if the database is not created before, it will be automatically created. you can also use $ m -... ">
PHP connection to MongoDB example:
// Use the default p
The importance of database backup and data recovery, I think you know, here is an example of how to manipulate data backups, examples of data recovery:
Creating test data
Create Db:testdb,collection:user, insert 10 records
MONGO MongoDB Shell version:3.0.2 connecting to:test > Use TestDB switched to DB TestDB > Db.user.insert ({id:1,na
Me: "User 1"});
Writeresult ({"ninserted": 1}) > Db.user.insert (
In the following example, two shared services, one Configuration Service and one mongos service are enabled. All these services are tested on the same server. Of course, they can also be deployed on different servers.1. Create a Shards instance
Start a pair of shared services on the local machine
$ Mkdir/data/db/a/data/db/B
$./Mongod -- shardsvr -- dbpath/data/db/a -- port 10000>/tmp/sharda. log
$ Cat/tmp/sharda. log
$./Mongod -- shardsvr -- dbp
,
age:string
});
var MyModel = Conn.model (' user ', user);
/* GET index listing. *
/Router.get ('/', function (req, res, next) {
Mymodel.findone ({name: "Zhangangs"}, function (err, user) {
console.log (user);
Res.render (' index ', {title: ' Express ', User:user});})
;
Module.exports = router; Modify Wiew/index.ejs Restart the server, refresh the page, the effect is as follows: Complete, (>_ The pro-test is available. Attention:1. The third step connects the da
database does not have the TRANS.SP table to import successfully before the import is performed; the Mongoexport and mongoimport are required to enter a different sequence of parameters; for the replica set, Mongoexport Data export can be either a primary node in a replica set, or a secondary node, and for a replica set, the Mongoimport data import must be a primary node; For export of large amounts of data, there is no production problem with mongoexport operation. For imports of large amounts
Tags:. JSON name UPD let bar java.net and start turnFirst import the MongoDB jar package Http://pan.baidu.com/s/1bnGMJRD Database.java Package com.mongodb.test; Import java.net.UnknownHostException; Import Com.mongodb.DB;Import com.mongodb.DBCollection;Import Com.mongodb.DBCursor;Import Com.mongodb.DBObject;Import Com.mongodb.Mongo;Import com.mongodb.MongoException;Import Com.mongodb.util.JSON; public class DataBase {public static void Main (string[]
("4c220a42f3924d31102bd856"), "X": 4, "J": 1} ...
In the MongoDB shell, we can also use cursors as arrays:
> var cursor = db.things.find ();> Printjson (cursor[4]);{"_id": ObjectId ("4c220a42f3924d31102bd858"), "X": 4, "J": 3}
When using cursors, be aware of memory-consuming problems, especially large cursor objects, which may overflow memory. So shouldThe iteration is the way to output. The following example
=Req.body.useremail; varCollection = Db.get (' users '); Collection.insert ({"Name": Username,"Email": UserEmail},function(err, doc) {if(Err) {Res.send (' There is a problem adding the information to the DB. '); } Else{res.location (' UserList '); Res.redirect (' UserList '); } }); };}Routes/user.jsfunction (req, res) { res.send (' respond with a resource ');}Views/index.jadeextends Layoutblock content h1= title p Welcome to #{title}Views/hello.jadeextends Layoutblock content
",
"Joe@gmail.com"
],
"username": "Joe"
}
--In an array, the subscript for the first element is 0, and then grows sequentially. The following example is to label the array as 1
--the element value of the second element is modified to the new value.
gt; db.blog.update ({"username": "Joe"}, {"$set": {"emails.1": "Joe@example.com"}})
gt; Db.blog.findOne ()
{
"_id": ObjectId ("4fd2e468b2ac404941134bed"),
"Emails": [
"Joe@gmail.com",
"Joe@exam
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.