How to remove collection named 'group'? - mongodb

I accidentally created a collection named 'group'.
How do I remove it.
When I give the following in the mongo console
db.group.drop()
I get the following error
Fri Jun 7 16:36:39.630 JavaScript execution failed: TypeError: Object function ( parmsObj ){
var ret = this.runCommand( { "group" : this._groupFixParms( parmsObj ) } );
if ( ! ret.ok ){
throw "group command failed: " + tojson( ret );
}
return ret.retval;
} has no method 'drop'

The problem is that group is a method on a database object. So, db.group cannot be used to get the actual collection named group. Instead, use .getCollection():
db.getCollection('group').drop()

Related

How to insert multiple row in dynamoDb using PHP?

I have written below Json for insert in dynamodb, but unable to insert. But if I try single element without array it's working fine.
$item = $marshaler->marshalJson('
[
{
"PK":"CATG",
"SK":"NAME#SMART_PHONE",
"TYPE":"CATG",
"ATTR":{
"name":"安いスマートフォン一覧【最安値比較】"
}
},
{
"PK":"CATG#SMART_PHONE",
"SK":"SUBCATG#IPHONE",
"TYPE":"SUBCATG",
"ATTR":{
"name":"IPHONE",
"Compa":"mac",
"uid":123
}
},
{
"PK":"CATG#SMART_PHONE#SUBCATG#IPHONE",
"SK":"PROD#PHONE11",
"TYPE":"PROD",
"ATTR":{
"name":"PHONE11",
"uid":123,
"price":112.02,
"images":[
],
"total":120
}
},
{
"PK":"CATG#SMART_PHONE#SUBCATG#IPHONE",
"SK":"PROD#PHONE7",
"TYPE":"PROD",
"ATTR":{
"name":"PHONE7",
"Compa":"mac",
"uid":124,
"price":102.02,
"images":[
],
"total":80
}
}
]
');
$params = [
'TableName' => $tableName,
'Item' => $item
];
$result = $dynamodb->putItem($params);
After apply this code.
I have got below error
Fatal error: Uncaught InvalidArgumentException: The JSON document must be valid and be an object at its root. in E:\xampp\htdocs\shop\vendor\aws\aws-sdk-php\src\DynamoDb\Marshaler.php:99 Stack trace: #0 E:\xampp\htdocs\shop\item.php(30): Aws\DynamoDb\Marshaler->marshalJson('\r\n [\r\n ...') #1 {main} thrown in E:\xampp\htdocs\shop\vendor\aws\aws-sdk-php\src\DynamoDb\Marshaler.php on line 99
If I insert single row it's working fine. How can I insert bulk row ?
To insert multiple items you have two options:
you can have a loop and repeatedly call the PutItem API for each one
you can break up your collection of items into groups of up to 25 and use the BatchWriteItem API (see docs)
Note that the BatchWriteItem API will still result in 25 WCU being used but it just saves you a bit on the network round-trips, making fewer calls.
The downside of using BatchWriteItem is that you have to manage the grouping of items and then handle the partial successful writes, such that unsuccessful items get re-grouped/re-tried.

Hash entry sometime is $NULL (error), and sometimes isn't?

I have my little 3-sided socket-server. Each server has its own hash with its key-values.
The very first is:
$Local = #{ID="Local"; ...}
$RemtA = #{ID="RemtA"; ...}
$RemtB = #{ID="RemtB"; ...}
I start for all of the the listeners - no problem.
If now a client wants to connect, I want to add the ID to $ProgressHead, which is defined like this:
$ProgressHead = "Value-Broadcast, Connected: "
and used in my function to accept a client called with its hash as $h:
if ( !$h.Connected ) {
#Write-Host "$($h.ID) not connected, pending: $($h.listener.Pending())"
if ( $h.listener.Pending()) {
$h.client = $h.listener.AcceptTcpClient() # will block here until connection
$h.stream = $h.client.GetStream();
$h.writer = New-Object System.IO.StreamWriter $h.stream
$h.writer.AutoFlush = $true
$h.Connected = $true
Write-Host $Global:ProgressHead # fails - empty ??
Write-Host $h.ID # prints oh depit it is marked as error
if ( !$Global:ProgressHead.Contains( $h.ID ) ) { # <= HERE IS THE ERROR ????
$Global:ProgressHead= "$($Global:ProgressHead)$($h.ID) "
}
}
}
The Error message says:
Can't call a method for an expression which is NULL and $h.ID is underlined
BUT I DO NOT get any error if I start this either in the cmd-console when running powershell -file ThreeServer.ps1 or within the ISE in debug mode. The ID is written correctly to $ProgressHead!
Only if I start this in the Powershell console (PS C:\...> ./ThreeServer.ps1) I get this error, but all the other keys in the lines above are valid ONLY $h.ID on ONLY the PS-console throws this error?

How to detect an error in mapreduce

Let's have an "error_test.js" file that contains:
db = db.getMongo().getDB( "mydb" );
db.mycol.insert( { hello : "world" } );
print("it is shown");
db.runCommand(
{
mapReduce: "mycol",
map: function(){ print(not_exists); },
reduce: function(key, values){},
out: { replace: "myrescol" }
}
);
print("it is shown too (after error in mapreduce!)");
If I run the file (in Windows command line), I get:
mypath>mongo error_test.js
MongoDB shell version: 2.4.0
connecting to: test
it is shown
it is shown too (after error in mapreduce!)
mypath>echo %errorlevel%
0
mypath>
So we can deduce that:
the mapreduce error doesn't stop the execution.
the mapreduce error is not shown to the user.
the mapreduce error is not translated to the exit code (0 = success) (so a caller program can't detect the error).
The only way to know of the error is by looking for the following line at "mongod.log":
Wed Jun 12 10:02:37.393 [conn14] JavaScript execution failed: ReferenceError: not_exists is not defined near '(){ print(not_exists)'
Same happens if we use the "db.doEval(my_js)" method in Java and we put the content of "error_test.js" file into the "my_js" variable: The mapreduce error is not detected (no excepcion is launched, no null value is returned, "ok : 1.0" appears in the response).
So my question is: How can I detect an error in the mapreduce? (both in a js file and in the doEval() method)
Thank you
You need to capture the return document from db.runCommand() into a variable and then check its ok value in your script - you can then throw an error or print output, etc.
print("it is shown");
var res = db.runCommand(
{
mapReduce: "mycol",
map: function(){ print(not_exists); },
reduce: function(key, values){},
out: { replace: "myrescol" }
}
);
printjson(res);
if (res.ok == 0) {
print("Oopsy!");
throw("error! " + res.errmsg + " returned from mapreduce");
}
print("it is shown too (after error in mapreduce!)");

Is it possible to pass a javascript function in the scope parameter of the Collection.map_reduce in pymongo?

Given:
jstrMap = """
function() {
print("isPointInside = " + isPointInside);
print("polygon = " + polygon);
emit(this._id, this);
}
"""
jstrReduce = """
function(key, values) {
return values[0];
}
"""
def readJSCodeFromFile(filePath):
with open(filePath) as f:
return Code(f.read())
jsIsPointInside = readJSCodeFromFile(path.join(path.dirname(__file__), 'IsPointInside.js'))
IsPointInside.js:
function(pt, poly) {
}
And I invoke map_reduce like this:
mycoll.map_reduce(jstrMap, jstrReduce, 'results',
scope = {'isPointInside': jsIsPointInside, 'polygon': [[-77, 39], [-77,38], [-78,38], [-78,39]]})
Here is what I get on the client console:
db assertion failure, assertion: 'map invoke failed: JS Error: TypeError: isPointInside is not a function nofile_b:3', assertionCode: 9014
And the server output is:
isPointInside = null
polygon = -77,39,-77,38,-78,38,-78,39
Sun Apr 01 16:29:14 [conn11] JS Error: TypeError: isPointInside is not a function nofile_b:3
Sun Apr 01 16:29:14 [conn11] mr failed, removing collection :: caused by :: 9014 map invoke failed: JS Error: TypeError: isPointInside is not a function nofile_b:3
Debugging the python code reveals that jsIsPointInside is of type Code, as expected. str(jsIsPointInside) returns the function text, i.e. 'function(pt, poly) {\n}\n'
I do not want to populate the system.js collection, I'd like to pass the function in the scope. Is it possible at all?
Thanks.
Scope is an object where the fields are placed in the MapReduce scope as variables w/ the field name.
If you'd like to put a function in scope, you need to make it a value a field e.g.
scope = {
myFunc: function() { return "Foo";}
}

PowerShell webdeploy

I'm trying to use PowerShell with web deployment based on this
article
This is how my script looks like
[System.Reflection.Assembly]::LoadWithPartialName("Microsoft.Web.Deployment")
function Sync-Provider($provider, $sourceLocation, $destLocation)
{
$destBaseOptions = new-object Microsoft.Web.Deployment.DeploymentBaseOptions
$syncOptions = new-object Microsoft.Web.Deployment.DeploymentSyncOptions
Try
{
$deploymentObject = [Microsoft.Web.Deployment.DeploymentManager]::CreateObject($provider, $sourceLocation)
$deploymentObject.SyncTo($provider,$destLocation,$destBaseOptions,$syncOptions)
}
Catch
{
echo "EXCEPTION THROWN::[ $_ ] "
#throw $_
}
}
Sync-Provider ("apphostConfig","D:\NerdDinner_2.0\NerdDinner","c:\inetpub\wwwroot")
Running this gives the following exception
EXCEPTION THROWN::[ Cannot convert argument "0", with value: "System.Object[]",
for "CreateObject" to type "Microsoft.Web.Deployment.DeploymentWellKnownProvid
er": "Cannot convert value "apphostConfig,D:\NerdDinner_2.0\Ne
rdDinner,c:\inetpub\wwwroot" to type "Microsoft.Web.Deployment.DeploymentWellKn
ownProvider" due to invalid enumeration values. Specify one of the following en
umeration values and try again. The possible enumeration values are "Unknown, A
ppHostConfig, AppHostSchema, AppPoolConfig, ArchiveDir, Auto, Cert, ComObject32
, ComObject64, ContentPath, CreateApp, DirPath, DBFullSql, DBMySql, FilePath, G
acAssembly, IisApp, MachineConfig32, MachineConfig64, Manifest, MetaKey, Packag
e, RecycleApp, RegKey, RegValue, RootWebConfig32, RootWebConfig64, RunCommand,
SetAcl, WebServer, WebServer60"." ]
Could you give me some hints on this, please?
Try to enclose the first parameter [Microsoft.Web.Deployment]::DeploymentWellKnownProvider.AppHostConfig with a pair of extra parenthesis: ([Microsoft.Web.Deployment]::DeploymentWellKnownProvider.AppHostConfig).
In my case I had the same problem, just opened the powershell console as Administrator and it worked.