我正在尝试将图片上传到我的S3存储桶.我正在使用AngularJS v1.2.13.当我使用他们的文档中显示的简单案例(提交带action标签的表单)时,一切正常.但是,如果我想这样做,Angular的Angular方式会ng-click发送OPTIONS请求而不是POST请求.
以下是服务代码,它首先到服务器获取签名(我知道该部分没问题)然后尝试POST所有内容.
myServices.factory('s3', function($http) {
var service = {};
service.upload = function(fileName) {
return $http(
{
method:"POST",
url: "sign",
data: { "fileName": fileName }
}
).then(
function(result) {
// success
//resolve the promise as the data
var data = result.data;
var url = "https://" + data.bucket + ".s3.amazonaws.com/";
return $http.post(url, {
"key": data.key,
"AWSAccessKeyId": data.awsKey,
"acl": data.acl,
"policy": data.policy,
"signature": data.signature,
"Content-Type": "image/jpeg",
"success_action_redirect": "http://localhost:3000/s3Uploaded"
}).then(
function(response) {
// success
console.log("s3.upload, …Run Code Online (Sandbox Code Playgroud) 如何根据布尔字段对查询结果进行排序?
考虑以下集合:
{ "_id" : ObjectId("..."), "name" : "John" , "isFoo" : true}
{ "_id" : ObjectId("..."), "name" : "Jim" , "isFoo" : false}
{ "_id" : ObjectId("..."), "name" : "Joel" , "isFoo" : false}
{ "_id" : ObjectId("..."), "name" : "Jill" , "isFoo" : true}
{ "_id" : ObjectId("..."), "name" : "Samantha" , "isFoo" : true}
Run Code Online (Sandbox Code Playgroud)
我需要一个将返回第isFoo == true一个和isFoo == false第二个文档的查询.换句话说,我需要按布尔字段排序.
下面的代码不起作用,因为我仍然得到一些isFoo == true与假的混合的文档.
db["users"].find().sort( { isFoo: 1 } )
Run Code Online (Sandbox Code Playgroud)
想法?