<commit_before>class MongodbRestEngine::BucketCollectionItemsController < ApplicationController

  before_filter :load_collection
  
  def index
    keyz = []
    @collection.find().each do |key|
      keyz << key
    end
    
    render :text => keyz.to_json
  end
  
  def show
    render :text => @collection.find_one({:_id => BSON::ObjectId(params[:id])}).to_json
  end

  def create
    render :text => @collection.save(JSON.parse(params[:document])).to_json
  end

  def update
    render :text => @collection.update({:_id => BSON::ObjectId(params[:id])}, 
                                        JSON.parse(params[:document])).to_json
  end

  def destroy
    render :text => @collection.remove({:_id => BSON::ObjectId(params[:id])}).to_json
  end
  
  private
  
  def load_collection
    connection = Mongo::Connection.from_uri(MongodbRestEngine.backend_uri,
                                            {:pool_size => MongodbRestEngine.pool_size,
                                             :timeout => MongodbRestEngine.timeout})
    db = connection.db(MongodbRestEngine.db_name)

    @collection = db.collection("#{params[:bucket]}_#{params[:collection]}")
  end
<commit_msg>use # as separator<commit_after>class MongodbRestEngine::BucketCollectionItemsController < ApplicationController

  before_filter :load_collection
  
  def index
    keyz = []
    @collection.find().each do |key|
      keyz << key
    end
    
    render :text => keyz.to_json
  end
  
  def show
    render :text => @collection.find_one({:_id => BSON::ObjectId(params[:id])}).to_json
  end

  def create
    render :text => @collection.save(JSON.parse(params[:document])).to_json
  end

  def update
    render :text => @collection.update({:_id => BSON::ObjectId(params[:id])}, 
                                        JSON.parse(params[:document])).to_json
  end

  def destroy
    render :text => @collection.remove({:_id => BSON::ObjectId(params[:id])}).to_json
  end
  
  private
  
  def load_collection
    connection = Mongo::Connection.from_uri(MongodbRestEngine.backend_uri,
                                            {:pool_size => MongodbRestEngine.pool_size,
                                             :timeout => MongodbRestEngine.timeout})
    db = connection.db(MongodbRestEngine.db_name)

    @collection = db.collection("#{params[:bucket]}##{params[:collection]}")
  end

{'fraction_non_alphanumeric': 0.12442202606137033, 'fraction_numerical': 0.0, 'mean_word_length': 2.617021276595745, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 23, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 10, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5327251', 'n_tokens_mistral': 697, 'n_tokens_neox': 674, 'n_words': 122}