Skip to content

Instantly share code, notes, and snippets.

View zolzaya's full-sized avatar

Zolzaya Erdenebaatar zolzaya

View GitHub Profile
sudo rm /var/lib/mongodb/mongod.lock
sudo -u mongodb mongod -f /etc/mongodb.conf --repair
sudo start mongodb
> db.help()
DB methods:
db.addUser(username, password[, readOnly=false])
db.auth(username, password)
db.cloneDatabase(fromhost)
db.commandHelp(name) returns the help for the command
db.copyDatabase(fromdb, todb, fromhost)
db.createCollection(name, { size : ..., capped : ..., max : ... } )
db.currentOp() displays the current operation in the db
db.dropDatabase()
> db.users.help()
DBCollection help
db.users.find().help() - show DBCursor help
db.users.count()
db.users.dataSize()
db.users.distinct( key ) - eg. db.users.distinct( 'x' )
db.users.drop() drop the collection
db.users.dropIndex(name)
db.users.dropIndexes()
db.users.ensureIndex(keypattern[,options]) - options is an object with these possible fields: name, unique, dropDups
> db.system.js.save({_id:"last_n_users", value: function(n){return db.users.find().sort({created_at:-1}).limit(n).toArray()}})
> db.eval("last_n_users(3)")
[
{
"_id" : ObjectId("4e8c2a00de570598c220878b"),
"username" : "Zoloo",
"created_at" : ISODate("2011-10-04T16:00:00Z"),
"password" : "secret",
"last_visited_at" : ISODate("2011-10-04T16:00:00Z")
},
# Өгөгдөл 1
овог: Болд
нэр: Отгонхүү
хүйс: эрэгтэй
хаяг: БГД 2-5-4 тоот
# Өгөгдөл 2
нэр: Номин
хүйс: эмэгтэй
@zolzaya
zolzaya / gist:1868239
Created February 20, 2012 07:17
Native method in Java
private native void nativeMe()
{
// Энд доод түвшний кодоо бичээрэй.
}
@zolzaya
zolzaya / application.js.coffee
Last active December 15, 2015 04:29
Single Page Application-д зориулсан хамгийн энгийн, хандан эрх шалгах класс
# Hooks
unless Array::unique
Array::unique = ->
output = {}
output[@[key]] = @[key] for key in [0...@length]
value for key, value of output
unless Array::contains_array
Array::contains_array = (arr)->
@.every (val)->
var Ability, ability, as_array, is_array, is_array_contains_array;
if (!Array.prototype.unique) {
Array.prototype.unique = function() {
var key, output, value, _i, _ref, _results;
output = {};
for (key = _i = 0, _ref = this.length; 0 <= _ref ? _i < _ref : _i > _ref; key = 0 <= _ref ? ++_i : --_i) {
output[this[key]] = this[key];
}
_results = [];
@zolzaya
zolzaya / category
Last active December 15, 2015 18:09
Nested category
За тэгвэл чадлынхаа хэрээр тайлбарлах гээд үзье: Ангилалуудаа categories гэсэн хүснэгтэнд хадгальяа,
тэр хүснэгт нь id, name, ancestry гэсэн талбаруудтай.
Хамгийн эхний өгөгдөл буюу A-г хийхэд дараах байдалтай болно.
id|name|ancestry
1|A|null
Өөрөөр хэлбэл A нь root болно. Одоо B-г нэмвэл:
id|name|ancestry
@zolzaya
zolzaya / schema.rb
Created May 3, 2013 08:02
schema.rb
# encoding: UTF-8
# This file is auto-generated from the current state of the database. Instead
# of editing this file, please use the migrations feature of Active Record to
# incrementally modify your database, and then regenerate this schema definition.
#
# Note that this schema.rb definition is the authoritative source for your
# database schema. If you need to create the application database on another
# system, you should be using db:schema:load, not running all the migrations
# from scratch. The latter is a flawed and unsustainable approach (the more migrations
# you'll amass, the slower it'll run and the greater likelihood for issues).