Mongoid.master.collection("seq").find_and_modify({
:query => {:_id => self.class.name},
:update => {'$inc' => {:next => 1}},
:new => true,
:upsert => true
})["next"]
It works well in mongoid 2.4.9, but when i use mongoid 3.0.0, i got error
NoMethodError in PostsController#new
undefined method `master' for Mongoid:Module
Mongoid 3.0.0 does not support Mongoid.master ?
Because Mongoid 3.0.0 was use Moped to instead Mongo Ruby Driver, So the old API can't call not.
You can try this:
Mongoid::Sessions.default.command({:findAndModify => "seq",
:query => { :_id => self.class.name },
:update => { "$inc" => { :next => 1 } },
:upsert => true,
:new => true })
And you can use this Gem to do Auto increment id feature:
https://github.com/huacnlee/mongoid_auto_increment_id
Related
Tried this, but couldn't get the desired output. I want to find documents without an array or a array smaller than 4.
db.collection.find({
'text' => { '$exists' => true },
'tags' => {
'$or' => [
{ '$exists' => false },
{ '$lt' => ['$size', 4] }
]
}
})
Error is:
unknown operator: $or
The $or operator should be at the top level, with an array of complete predicates:
db.collection.find({
'text' => { '$exists' => true },
'$or' => [
{'tags' => { '$exists' => false },
{'tags' => { '$lt' => ['$size', 4] }
]
})
I am new to this stuff. I just inherited this olde system! I managed to get Solr running, and am trying to execute some old code that rebuilds the Solr data. The client ping is failing and I don't understand why.
Here is the code that is trying to initiate a re-index
// these are correct, now Solarium is falling over
// with a 404. pile of junk
print(SOLR_SERVER_HOSTNAME . "\n");
print(SOLR_SERVER_PORT . "\n");
print(SOLR_SERVER_CORE . "\n");
$options = array(
'adapteroptions' => array(
'host' => SOLR_SERVER_HOSTNAME,
'port' => SOLR_SERVER_PORT,
'core' => SOLR_SERVER_CORE,
'timeout' => 60
)
);
}
try {
// Ping the Solr server to check its availability
// create a new client. This seems to work
$this->client = new Solarium_Client($options);
if ($this->client) {
print("Solarium returned something \n");
print_r($this->client);
print("\n");
} else {
echo 'Solarium screwed the pooch';
}
// and create a ping whatever that means
// this also seems to work
$ping = $this->client->createPing();
if ($ping) {
print("ping creation worked \n");
print_r($ping);
} else {
print("ping creation failed \n");
}
// this always fails and terminate the
// program run
$this->client->ping($ping);
} catch (Solarium_Exception $e) {
print("exeption from ping request \n");
throw $e;
}
print("about to reset \n");
// Reset all filters and queries and process request params if requested
$this->reset($request);
}
The Solr admin screen is up. I have an empty collection1..
Here is the output from the trace I stuck in here
1/tmp/reindex.lock
15/01/18 17:38:54 [INFO] Index started
Index started
localhost
9999
collection1
Solarium returned something
Solarium_Client Object
(
[_options:protected] => Array
(
[adapter] => Solarium_Client_Adapter_Http
[adapteroptions] => Array
(
[host] => localhost
[port] => 9999
[core] => collection1
[path] => /solr/
[timeout] => 60
)
)
[_queryTypes:protected] => Array
(
[select] => Array
(
[query] => Solarium_Query_Select
[requestbuilder] => Solarium_Client_RequestBuilder_Select
[responseparser] => Solarium_Client_ResponseParser_Select
)
[update] => Array
(
[query] => Solarium_Query_Update
[requestbuilder] => Solarium_Client_RequestBuilder_Update
[responseparser] => Solarium_Client_ResponseParser_Update
)
[ping] => Array
(
[query] => Solarium_Query_Ping
[requestbuilder] => Solarium_Client_RequestBuilder_Ping
[responseparser] => Solarium_Client_ResponseParser_Ping
)
[mlt] => Array
(
[query] => Solarium_Query_MoreLikeThis
[requestbuilder] => Solarium_Client_RequestBuilder_MoreLikeThis
[responseparser] => Solarium_Client_ResponseParser_MoreLikeThis
)
[analysis-document] => Array
(
[query] => Solarium_Query_Analysis_Document
[requestbuilder] => Solarium_Client_RequestBuilder_Analysis_Document
[responseparser] => Solarium_Client_ResponseParser_Analysis_Document
)
[analysis-field] => Array
(
[query] => Solarium_Query_Analysis_Field
[requestbuilder] => Solarium_Client_RequestBuilder_Analysis_Field
[responseparser] => Solarium_Client_ResponseParser_Analysis_Field
)
[terms] => Array
(
[query] => Solarium_Query_Terms
[requestbuilder] => Solarium_Client_RequestBuilder_Terms
[responseparser] => Solarium_Client_ResponseParser_Terms
)
[suggester] => Array
(
[query] => Solarium_Query_Suggester
[requestbuilder] => Solarium_Client_RequestBuilder_Suggester
[responseparser] => Solarium_Client_ResponseParser_Suggester
)
)
[_pluginTypes:protected] => Array
(
[loadbalancer] => Solarium_Plugin_Loadbalancer
[postbigrequest] => Solarium_Plugin_PostBigRequest
[customizerequest] => Solarium_Plugin_CustomizeRequest
[parallelexecution] => Solarium_Plugin_ParallelExecution
[bufferedadd] => Solarium_Plugin_BufferedAdd
[prefetchiterator] => Solarium_Plugin_PrefetchIterator
)
[_pluginInstances:protected] => Array
(
)
[_adapter:protected] =>
[_requestBuilders:protected] =>
)
ping creation worked
Solarium_Query_Ping Object
(
[_options:protected] => Array
(
[resultclass] => Solarium_Result_Ping
[handler] => admin/ping
)
[_helper:protected] =>
[_params:protected] => Array
(
)
)
exeption from ping request
Failed to initialise Solr client:
Solr HTTP error: Not Found (404)
Failed to initialise Solr client: Solr HTTP error: Not Found (404)
Any hints? It's the first time I have seen this stuff.
Cheers,
Mark.
Fixed. The core name was getting flattened in another bit of code. Two constants for the same property. Two different values! – Addinall 22 secs
I'm currently using DB-Transaction and it throws Lexical variable error
attached here is my code:
DB::transaction(function ($request) use ($request) {
$salesman = new Salesman([
'operation_id' => $request->get('operation_id'),
'warehouse_id' => $request->get('warehouse_id'),
'salesman_name' => $request->get('salesman_name'),
'address' => $request->get('address'),
'contact_number' => $request->get('contact_number'),
'email_address' => $request->get('email_address'),
'area_id' => 'pending',
]);
$salesman->save();
});
return view('salesman.index');
}
It is working now after I remove the $request parameter in function
DB::transaction(function () use ($request) {
$salesman = new Salesman([
'operation_id' => $request->get('operation_id'),
'warehouse_id' => $request->get('warehouse_id'),
'salesman_name' => $request->get('salesman_name'),
'address' => $request->get('address'),
'contact_number' => $request->get('contact_number'),
'email_address' => $request->get('email_address'),
'area_id' => 'pending',
]);
$salesman->save();
});
return view('salesman.index');
}
I use smarty to display different code and I want to check if the array of some phrase contains more than 1 items.
I want to create a if phrase, that checks if the array contains only 1 value or more. Something like this, but of course that correct.
{if $domains|#array < 1}
How can I achieve that?
The code looks like this:
$domains
Smarty_Variable Object (3)
->value = Array (3)
0 => Array (17)
domain => "example1.com"
regperiod => "1"
dnsmanagement => "on"
emailforwarding => ""
idprotection => ""
addonsCount => 1
eppvalue => ""
fields => Array (0)
configtoshow => true
hosting => false
1 => Array (17)
domain => "example2.com"
regperiod => "1"
dnsmanagement => "on"
emailforwarding => ""
idprotection => ""
addonsCount => 1
eppvalue => ""
fields => Array (0)
configtoshow => true
hosting => false
2 => Array (17)
domain => "example3.com"
regperiod => "1"
dnsmanagement => "on"
emailforwarding => ""
idprotection => ""
addonsCount => 1
eppvalue => ""
fields => Array (0)
configtoshow => true
hosting => false
->nocache = false
You can use count (from the php function http://php.net/manual/es/function.count.php):
{if $domains|#count < 1}
About 1 out of every 10 queries seem to return a communication error even though the solr server is up. (I verified this by removing my ->ping() check and all the queries worked.
What could be causing ping to have a communication error?
Apache_Solr_Response::__set_state(array(
'_response' =>
Apache_Solr_HttpTransport_Response::__set_state(array(
'_statusCode' => 0,
'_statusMessage' => 'Communication Error',
'_mimeType' => 'text/plain',
'_encoding' => 'UTF-8',
'_responseBody' => '',
)),
'_isParsed' => false,
'_parsedData' => NULL,
'_createDocuments' => true,
'_collapseSingleValueArrays' => true,
))
The default timeout is 2 seconds, I changed to 10 and it is working now.