mongodb

MongoDB driver for Haxe
http://github.com/MattTuttle/mongo-haxe-driver

To install, run:

haxelib install mongodb 0.9.0 

See using Haxelib in Haxelib documentation for more information.

README.md

Build Status

MongoDB driver for Haxe

This is a database driver for MongoDB written in Haxe and available for all targets allowing a socket connection (neko/php/cpp).

Find all objects in a collection

Finding rows in a relational database can be a daunting process. Thankfully with Mongo it's just like accessing a regular Haxe object instance.

import org.mongodb.Mongo;

class Main
{
	public static function main()
	{
		var mongo = new Mongo();       // connects to MongoDB
		var posts = mongo.blog.posts;  // get the "blog.posts" collection

		// loops through all objects in "test.posts"
		for (post in posts.find())
		{
			trace(post.title); // assumes that all posts have a title
		}
	}
}

Inserting and updating

Inserting object in Mongo is just as simple as putting values in an Array. Just create an object and put it in the collection by calling insert(). Updating objects is just as simple except we need a way to find the original object so we pass a selector object first.

import org.mongodb.Mongo;

class Main
{
	public static function main()
	{
		var mongo = new Mongo();       // connects to MongoDB
		var posts = mongo.blog.posts;  // get the "blog.posts" collection

		// creating a new post is as easy as making a new object
		var post = {
			title: 'My awesome post',
			body: 'MongoDB is easy as pie'
		};
		posts.insert(post); // save the post in Mongo

		post.body = 'Made some updates to my post';
		posts.update({title: post.title}, post); // update the post
	}
}

Driver Roadmap

Here are the features planned for future versions.

  • Replica sets
  • Automatic reconnection
Contributors
heardtheword
Version
0.9.0
Published
3 years ago
License
MIT

All libraries are free

Every month, more than thousand developers use haxelib to find, share, and reuse code — and assemble it in powerful new ways. Enjoy Haxe; It is great!

Explore Haxe

Haxe Manual

Haxe Code Cookbook

Haxe API documentation

You can try Haxe in the browser! try.haxe.org

Join us on Github!

Haxe is being developed on GitHub. Feel free to contribute or report issues to our projects.

Haxe on Github